Create a configuration file and use PHP to write your own BLOG system 2_PHP tutorial

Source: Internet
Author: User
Tags flock
Create a configuration file and use PHP to write your BLOG System 2. First look at the file interface before the creation of the configuration file after the interface, will prompt that you can not install the following code again, the html interface code will not be available, directly on the PHP code copy first look

File interface before creation

After the configuration file is created, the system prompts that the installation cannot be repeated.

Let's go to the code below. the code on the html interface is no longer available. just go to the PHP code.

The code is as follows:


/*
FILE: install. php
Author: www.5dkx.com
DATE: 2010-3-29
DONE: install the configuration file
*/
If ($ _ POST [mysubmit])
{
$ Host = $ _ POST [hostname];
$ User = $ _ POST [user];
$ Passwd = $ _ POST [passwd];
$ Dbname = $ _ POST [dbname];
$ Siteurl = "http: //". $ _ POST [siteurl];
$ Sitekeyword =$ _ POST [sitekeyword];
$ Sitedescription = $ _ POST [sitedescription];
$ Sitename = $ _ POST [sitename];
If (! File_exists ("install_locak.txt "))
{
$ Fp = fopen ("./include/config. func. php", "w + ");
If (flock ($ fp, LOCK_EX ))
{
Fwrite ($ fp, "<"."? Php \ r \ n ");
Fwrite ($ fp, "\ $ host = \" $ host \ "; \ r \ n ");
Fwrite ($ fp, "\ $ user = \" $ user \ "; \ r \ n ");
Fwrite ($ fp, "\ $ passwd = \" $ passwd \ "; \ r \ n ");
Fwrite ($ fp, "\ $ dbname = \" $ dbname \ "; \ r \ n ");
Fwrite ($ fp, "\ $ sitename = \" $ sitename \ "; \ r \ n ");
Fwrite ($ fp, "\ $ siteurl = \" $ siteurl \ "; \ r \ n ");
Fwrite ($ fp, "\ $ sitekeyword = \" $ sitekeyword \ "; \ r \ n ");
Fwrite ($ fp, "\ $ sitedescription = \" $ sitedescription \ "; \ r \ n ");
$ Tmp = "\ $ conn = mysql_connect (\ $ host, \ $ user, \ $ passwd) or die (mysql_error (); \ r \ n ";
Fwrite ($ fp, $ tmp );
$ Tmp = "mysql_query (\" set names 'gbk' \ ") or die (\" failed to set the character Library! \ "); \ R \ n ";
Fwrite ($ fp, $ tmp );
$ Tmp = "mysql_select_db (\ $ dbname, \ $ conn) or die (\" failed to connect to the database! \ "); \ R \ n ";
Fwrite ($ fp, $ tmp );
Fwrite ($ fp, "?> \ R \ n ");
Flock ($ fp, LOCK_UN );
Echo "file configured successfully!
";
Echo"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.