Summary of common problems in PHP

xiaoxiao2021-03-06  19

Summary of common problems in PHP

If you have any error, you have better ideas, welcome to post.

Please check the PHP manual, MySQL manual, and the settings inside PHPinfo before you mention the question.

Also hope you read PHP programming standards

1: Why can't I get a variable?

I didn't get any value when I output $ Name when I output $ Name when I output $ NAME?

Register_global defaults to OFF in the version after php4.2

If you want to get the variable submitted from another page:

Method 1: Find register_global in php.ini and set it to ON.

Method 2: Put this EXTRACT ($ _ POST); Extract ($ _ get); (Note Extract ($ _ session) must have session_start ()).

Method 3: A read variable $ A = $ _ get ["a"]; $ b = $ _ post ["b"], etc., although this method is troubles, but is more secure.

2: Debug your program

You must know what a variable must be known at runtime. I did this, build a file debug.php, the content is as follows:

CODE:

[Copy to CLIPBOARD]

Ob_start ();

Session_start ();

Echo "

";

Echo "This page is _GET variables are:";

Print_r ($ _ get);

Echo "The _post variables obtained on this page are:";

Print_r ($ _ post);

Echo "The _cookie variable from this page is:";

Print_r ($ _ cookie);

Echo "The _ssion variables obtained on this page are:";

Print_r ($ _ session);

ECHO "";

?>

Then set in php.ini: include_path = "c: / PHP" and put the debug.php in this folder.

You can include this file in each page, view the obtained variable name and value.

3: How to use session

Anyone is related to session, you must call the function session_start ();

Paying for the session is very simple, such as:

CODE:

[Copy to CLIPBOARD]

Session_start ();

$ Name = "This is a session example";

Session_register ("name"); // Notice, don't write: session_register ("$ name");

Echo $ _SESSION ["Name"];

// $ _SESSION ["name"] "This is a session example"

?>

After PHP4.2, you can pay for the session:

CODE:

[Copy to CLIPBOARD]

Session_start ();

$ _SESSION ["Name"] = "Value";

?>

Cancel session can be like this:

CODE:

[Copy to CLIPBOARD]

session_start ();

session_unset ();

session_destroy ();

?>

Cancel a session variable has bugs above PHP4.2 or more.

note:

1: There is no output before calling session_start (). For example, it is wrong.

========================================== 1 line

2 line

3 line session_start (); // has output in the first line

4 lines .....

5 line?>

=================================================================================================================================================================================

Tip 1:

Anyone who appears "...... Headers Already Sent ........", it is to output information to the browser before session_start ().

It is normal to remove the output, (Cookie will also have this error, the same reason is the cause of the error)

Tip 2:

If your session_start () is placed in the loop statement, and it is difficult to determine where to output information to the browser, you can use the following method:

1 line

........ Here is your program ...

2: What is wrong?

Warning: session_start (): Open (/ tmp / sess_7d190aa36b4c5ec13a5c1649cc2da23f, o_rdwr) failed: ....

Because you don't specify the storage path of the session file.

Solution:

(1) establish a folder TMP in the C drive

(2) Open php.ini, find session.save_path, modified to session.save_path = "c: / tmp"

4: Why do I send variables to another web page, I only get the first half, and all lost in space.

CODE:

[Copy to CLIPBOARD]

$ VAR = "Hello PHP"; // Modified to $ VAR = "Hello PHP"; try what results

$ pos = "Receive.php? Name =". $ VAR;

HEADER ("Location: $ POST");

?>

Receive.php content:

CODE:

[Copy to CLIPBOARD]

Echo "

";

Echo $ _Get ["name"];

ECHO "";

?>

The correct way is:

CODE:

[Copy to CLIPBOARD]

$ VAR = "Hello PHP";

$ pos = "Receive.php? Name =". Urlencode ($ VAR);

HEADER ("Location: $ POST");

?>

You don't need to use Urldecode () in the receiving page, and the variable will be automatically encoded.

5: How to intercept the specified length of Chinese characters without the end of "?>", Exceeding the part to "..." instead

In general, the variables to be intercepted come from mysql, first to ensure that the length is long enough, generally CHAR (200), can keep 100 Chinese characters, including punctuation.

CODE:

[Copy to CLIPBOARD]

$ Short_STR = Showsh ($ STR, 4); // Intercept 4 Chinese characters in front, the result is: this character ...

Echo "$ Short_STR";

Function Csubstr ($ STR, $ START, $ LEN)

{

$ Strlen = Strlen ($ STR);

$ clen = 0;

For ($ I = 0; $ I <$ Strlen; $ i , $ Clen )

{

IF ($ clen> = $ start $ g)

Break;

IF (Substr ($ Str, $ I, 1)> 0xA0)

{

IF ($ clen> = $ s)

$ Tmpstr. = Substr ($ STR, $ I, 2);

$ i ;

}

Else

{

IF ($ clen> = $ s)

$ Tmpstr. = SUBSTR ($ STR, $ I, 1);

}

}

Return $ TMPSTR;

}

Function Showsh ($ STR, $ LEN)

{

$ TEMPSTR = CSUBSTR ($ STR, 0, $ LEN);

IF ($ STR <> $ TEMPSTR)

$ Tempstr. = "..."; // What is the end of the end, modify it here.

Return $ TEMPSTR;

}

6: Specify your SQL statement

In the form, in front of the field, "` ", this will not occur because of misuse the keyword,

Of course I don't recommend you to use keywords.

E.g

$ SQL = "INSERT INTO` Xltxlm` (`Author`,` date`) Values ​​('XLTXLM', 'Use`', 1, 'criterion your sql string', '2003-07-11 00:00:00') "

"` "How to enter? On the Tab button.

7: How to make the string of the HTML / PHP format are not interpreted, but is displayed as an original

CODE:

[Copy to CLIPBOARD]

$ STR = "

php ";

Echo "is explained:" $ STR. "
processed:";

Echo Htmlentities (NL2BR ($ Str));

?>

8: How to get the variable value outside the function in the function

CODE:

[Copy to CLIPBOARD]

$ a = "php";

Foo ();

Function foo ()

{

Global $ a; // Delete here to see what results

Echo "$ a";

}

?>

9: How do I know what function is supported by default?

CODE:

[Copy to CLIPBOARD]

$ arr = get_defined_functions ();

Function PHP () {

}

Echo "

";

Echo "Here you display all functions supported by the system, and custom function PHP / N";

Print_r ($ ARR);

ECHO "";

?>

10: How to compare two dates a few days

CODE:

[Copy to CLIPBOARD]

$ DATE_1 = "2003-7-15"; // can also be: $ DATE_1 = "2003-6-25 23:29:14";

$ DATE_2 = "1982-10-1";

$ DATE_LIST_1 = EXPLODE ("-", $ DATE_1);

$ DATE_LIST_2 = EXPLODE ("-", $ DATE_2);

$ D1 = MKTIME (0, 0, 0. $ DATE_LIST_1 [1], $ DATE_LIST_1 [2], $ DATE_LIST_1 [0]);

$ D2 = MKTIME (0, 0, 0, $ DATE_LIST_2 [1], $ DATE_LIST_2 [2], $ DATE_LIST_2 [0]);

$ Days = ROUND (($ D1- $ D2) / 3600/24);

Echo "I have already struggled $ days day ^ _ ^";

?>

11: Why after I upgrade PHP, the original program appears full screen: undefined variable:

This is the meaning of warning, because the variable is not defined.

Open php.ini, find the bottom ERROR_REPORTING, modify to Error_Reporting = E_ALL & ~ E_NOTICE

For PARSE ERROR Error

Error_reporting (0) cannot be turned off.

If you want to close any error prompts, open php.ini, find display_errors, set to display_errors = off. After any errors will not be prompted later.

What is Error_Reporting?

12: I want to add a file in front of each file, but in the end. But a very troublesome added

1: Open the php.ini file

Set include_path = "C:"

2: Write two files

Auto_prepend_file.php and auto_append_file.php Save in the C drive, they will automatically attach to the head and tail of each PHP file.

3: Found in php.ini:

Automatically add files before or after any php document.

Auto_prepend_file = auto_prepend_file.php; attached to the head

Auto_APpend_file = auto_append_file.php; It is attached to the tail

After you will be equivalent to each PHP file

CODE:

[Copy to CLIPBOARD]

Include "auto_prepend_file.php";

....... / / Here is your program

INCLUDE "auto_append_file.php";

?>

13: How to use the PHP upload file

CODE:

[Copy to CLIPBOARD]

Upload File Form </ Title> </ Head></p> <p><body></p> <p><form encType = "Multipart / form-data" action = "" Method = "post"></p> <p>Please select a file: <br></p> <p><input name = "UPLOAD_FILE" type = "file"> <br></p> <p><Input Type = "Submit" Value = "Upload File"></p> <p></ form></p> <p></ body></p> <p></ html></p> <p><?</p> <p>$ upload_file = $ _ files ['upload_file'] ['tmp_name']; $ upload_file_name = $ _ files ['upload_file'] ['Name'];</p> <p>IF ($ UPLOAD_FILE) {</p> <p>$ file_size_max = 1000 * 1000; // 1M limit file upload maximum capacity (bytes)</p> <p>$ store_dir = "d: /"; // Upload file storage location</p> <p>$ accept_overwrite = 1; // Whether to allow overwriting the same file</p> <p>// Check file size</p> <p>IF ($ UPLOAD_FILE_SIZE> $ file_size_max) {</p> <p>Echo "Sorry, your file capacity is greater than the specified";</p> <p>EXIT;</p> <p>}</p> <p>// Check read and write files</p> <p>IF (file_exists ($ store_dir. $ upload_file_name) &&! $ accept_overwrite) {</p> <p>Echo "There is a file with the same file name";</p> <p>EXIT;</p> <p>}</p> <p>// Copy the file to the specified directory</p> <p>IF (! move_uploaded_file ($ upload_file, $ store_dir. $ upload_file_name) {</p> <p>Echo "copy file failed";</p> <p>EXIT;</p> <p>}</p> <p>}</p> <p>Echo "<p> You uploaded the file:";</p> <p>Echo $ _files ['UPLOAD_FILE'] ['Name'];</p> <p>Echo "<br>";</p> <p>// The original name of the client machine file.</p> <p>The MIME type of the echo file is: ";</p> <p>Echo $ _files ['UPLOAD_FILE'] ['Type'];</p> <p>/ / The MIME type of the file requires the browser to provide support for this information, such as "image / gif".</p> <p>Echo "<br>";</p> <p>ECHO "Upload File Size:";</p> <p>Echo $ _files ['UPLOAD_FILE'] ['Size'];</p> <p>// The size of the file has been uploaded, the unit is byte.</p> <p>Echo "<br>";</p> <p>The echo "file is uploaded and is temporarily stored as:";</p> <p>Echo $ _files ['UPLOAD_FILE'] ['TMP_NAME'];</p> <p>// The file is stored in the server after the file is uploaded.</p> <p>Echo "<br>";</p> <p>$ Erroe = $ _ files ['Upload_file'] ['Error'];</p> <p>Switch ($ Erroe) {</p> <p>Case 0:</p> <p>ECHO "Upload Success"; Break;</p> <p>Case 1:</p> <p>Echo "uploaded files exceeded the value restricted by the UPLOAD_MAX_FILESIZE option in php.ini.";</p> <p>Case 2:</p> <p>Echo "Upload file size exceeds the value specified by the max_file_size option in the HTML form."; BREAK;</p> <p>Case 3:</p> <p>Echo "file only partially upload"; "Break;</p> <p>Case 4:</p> <p>Echo "No file is uploaded"; BREAK;</p> <p>}</p> <p>?></p> <p>14: How to configure a GD library</p> <p>Below is my configuration process</p> <p>1: Use the dos command (you can also manually, copy all DLL files in the DLLS folder to the System32 directory) COPY C: / PHP / DLLS / *. DLL C: / Windows / System32 /</p> <p>2: Open php.ini</p> <p>Set extension_dir = "c: / php / extensions /"; 3:</p> <p>Extension = php_gd2.dll; remove the comma in front of Extension, if there is no PHP_GD2.DLL, php_gd.dll is the same, to ensure that this file C: /PHP/EXTensions/php_gd2.dll</p> <p>4: Run the following program for testing</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>OB_END_FLUSH ();</p> <p>// Note that you cannot output any information to your browser until you set whether auto_prepend_file is set.</p> <p>Header ("Content-Type: Image / PNG");</p> <p>$ IM = @ImageCreate (200, 100)</p> <p>OR DIE ("Unable to create images");</p> <p>$ background_color = imagecolorallocate ($ IM, 0, 0, 0);</p> <p>$ text_color = imagecolorallocate ($ IM, 230, 140, 150);</p> <p>ImageString ($ IM, 3, 30, 50, "A Simple Text String", $ text_color);</p> <p>ImagePNG ($ IM);</p> <p>?></p> <p>15: What is UBB code</p> <p>The UBB code is a variant of HTML, which is a special TAG that uses this procedure in many of the countries in China.</p> <p>Even if you are forbidden to use Ubbcode? Maybe you prefer to use ubbcode? Instead of HTML, even forums allow you to use HTML, because the code is less safer.</p> <p>Q3boy's UBB has an example, you can run test directly</p> <p>16: I want to modify the MySQL user, password</p> <p>First, you must declare a little, in most cases, modify MySQL is required to have root privileges in MySQL,</p> <p>So the general user cannot change the password unless the administrator is requested.</p> <p>method one</p> <p>Using phpMyadmin, this is the easiest, modify the User table of the MySQL library.</p> <p>But don't forget to use the Password function.</p> <p>Method Two</p> <p>Using mysqladmin, this is a special case of the previous declaration.</p> <p>mysqladmin -u root -p password mypasswd</p> <p>After entering this command, you need to enter the original password of the root, then the root's password will change to mypasswd.</p> <p>Change the root in the command to your username, you can change your own password.</p> <p>Of course, if your mysqladmin is connected to MySQL Server, or you have no way to execute mysqladmin.</p> <p>Then this way is invalid.</p> <p>And mysqladmin cannot empty your password.</p> <p>The following method is used under the MySQL prompt, and must have mysql root privileges:</p> <p>Method three</p> <p>Mysql> Insert Into MySQL.user (Host, User, Password)</p> <p>VALUES ('%', 'Jeffrey', Password ('Biscuit'));</p> <p>Mysql> Flush Privileges</p> <p>Specifically, this is increasing a user, the username is Jeffrey, the password is Biscuit.</p> <p>There is this example in the "MySQL Chinese Reference Manual", so I will write it.</p> <p>Note To use the Password function, then use Flush Privileges.</p> <p>Method 4</p> <p>Same three, just use the REPLACE statement</p> <p>Mysql> Replace Into mysql.user (Host, User, Password) VALUES ('%', 'Jeffrey', Password ('Biscuit'));</p> <p>Mysql> Flush Privileges</p> <p>Method 5</p> <p>Use the Set Password statement,</p> <p>Mysql> set password for jeffrey @ "%" = password ('biscuit');</p> <p>You must also use the Password () function,</p> <p>But don't need to use flush privileges.</p> <p>Method 6</p> <p>Use a grant ... identified by statement</p> <p>Mysql> grant usage on *. * to jeffrey @ "%" Identified by 'Biscuit'</p> <p>The password () function here is unnecessary, nor does it require Flush Privileges.</p> <p>Note: Password () [is not] The password encryption is applied to the same method encrypted at UNIX password.</p> <p>17: I want to know which website is connected to this page.</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>/ / Must be output through the super connection</p> <p>Echo $ _SERVER ['http_referer'];</p> <p>?></p> <p>18: Data is placed in the database and take it out to display what to pay attention to on the page</p> <p>Introduction</p> <p>$ Str = Addslashes ($ STR);</p> <p>$ SQL = "INSERT INTO` Tab` (`Content`) VALUES ('$ STR')"</p> <p>Outward</p> <p>$ Str = StripsLashs ($ STR);</p> <p>Display</p> <p>$ Str = HTMLSpecialchars (NL2BR ($ Str));</p> <p>19: How to read the current address bar information</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>$ s = "http: // {$ _server ['http_host']}: {$ _server [" server_port "]} {$ _ server ['script_name']}</p> <p>$ SE = '';</p> <p>Foreach ($ _GET AS $ Key => $ value) {</p> <p>$ SE. = $ key. "=". $ value. "&";</p> <p>}</p> <p>$ SE = preg_replace ("/( (.*));" $ 1 ", $ SE);</p> <p>$ SE? $ SE = "?" $ SE: "";</p> <p>Echo $ s. "$ se";</p> <p>?></p> <p>20: I click the back button, why do you fill in something before?</p> <p>This is because you use the session.</p> <p>Solution:</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>Session_Cache_Limiter ('private, must-revALIDATE');</p> <p>session_start ();</p> <p>...........</p> <p>........</p> <p>?></p> <p>21: How to display IP addresses in the picture</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><?</p> <p>Header ("Content-Type: Image / PNG");</p> <p>$ IMG = ImageCreate (180, 50);</p> <p>$ ip = $ _server ['Remote_Addr'];</p> <p>ImageColorTransparent ($ IMG, $ BGCOLOR); $ bgcolor = imagecolorallocate ($ IMG, 0x2C, 0x6D, 0xAF); // Background color</p> <p>$ shadow = imagecoloralloccate ($ IMG, 250, 0, 0); // Shadow Color</p> <p>$ textcolor = imagecolorallocate ($ IMG, OXFF, OXFF, OXFF); // Font Color</p> <p>ImageTfText ($ IMG, 10, 0, 78, 30, $ Shadow, "D: /Windows/fonts/tahoma.ttf", $ ip); // Display Background</p> <p>ImageTfText ($ IMG, 10, 0, 25, 28, $ TextColor, "D: /Windows/fonts/tahoma.ttf", "Your IP IS". $ IP); // Displays IP</p> <p>ImagePNG ($ IMG);</p> <p>ImageCreateFromPng ($ IMG);</p> <p>ImageDestroy ($ IMG);</p> <p>?></p> <p>22: How to get the real IP of the user</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><?</p> <p>Function iptype1 () {</p> <p>IF (GetENV ("http_client_ip") {</p> <p>Return GetENV ("http_client_ip");</p> <p>}</p> <p>Else {</p> <p>Return "None";</p> <p>}</p> <p>}</p> <p>Function iptype2 () {</p> <p>IF (GetENV ("http_x_forwarded_for")) {</p> <p>Return getenv ("http_x_forwarded_for");</p> <p>}</p> <p>Else {</p> <p>Return "None";</p> <p>}</p> <p>}</p> <p>Function iptype3 () {</p> <p>IF (GetENV ("remote_addr") {</p> <p>RETURN GETENV ("remote_addr");</p> <p>}</p> <p>Else {</p> <p>Return "None";</p> <p>}</p> <p>}</p> <p>Function IP () {</p> <p>$ ip1 = iptype1 ();</p> <p>$ IP2 = iptype2 ();</p> <p>$ IP3 = iptype3 ();</p> <p>IF (isset ($ IP1) && $ IP1! = "None" && $ ip1! = "unknown") {</p> <p>RETURN $ IP1;</p> <p>}</p> <p>Elseif (isset ($ IP2) && $ IP2! = "NONE" && $ IP2! = "unknown") {</p> <p>RETURN $ IP2;</p> <p>}</p> <p>Elseif (isset ($ IP3) && $ IP3! = "None" && $ IP3! = "unknown") {</p> <p>Return $ IP3;</p> <p>}</p> <p>Else {</p> <p>Return "None";</p> <p>}</p> <p>}</p> <p>Echo IP ();</p> <p>?></p> <p>23: How to read all records within three days from the database</p> <p>First, there is a DateTime field record time in the form.</p> <p>Format is '2003-7-15 16:50:00'</p> <p>Select * from `xltxlm` WHERE TO_DAYS (now ()) - to_days (` Date`) <= 3;</p> <p>24: How to Remote Link MySQL Database</p> <p>In the increase of the user's MySQL table, there is a Host field, modified to "%", or specify the IP address that allows the connection, so you can call remotely. $ LINK = mysql_connect ("192.168.1.80:3306", "root", "");</p> <p>25: After using Apache, the home page is garbled.</p> <p>method one:</p> <p>AddDefaultCharset ISO-8859-1 to AddDefaultCharset Off</p> <p>Method Two:</p> <p>AdddefaultCharset GB2312</p> <p>26: Why is single quotation marks, double quotes becomes (/ '/ ")</p> <p>Solution:</p> <p>Method 1: Set in php.ini: magic_quotes_gpc = OFF</p> <p>Method 2: $ STR = Stripcslashes ($ STR)</p> <p>27: How to let the program have been running, not more than 30 seconds</p> <p>SET_TIME_LIMIT (60) // The longest runtime is one minute</p> <p>SET_TIME_LIMIT (0) // Run to the program, or stop manual</p> <p>28: Calculate the current online number</p> <p>Example 1: Implementation with text</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>// First you have to read and write the authority</p> <p>// This program can be run directly, the first error, you can</p> <p>$ online_log = "count.dat"; // Save the file file,</p> <p>$ TIMEOUT = 30; // 30 seconds, no action, thinks to drop</p> <p>$ entries = file ($ online_log);</p> <p>$ TEMP = array ();</p> <p>For ($ I = 0; $ i <count ($ entries); $ i ) {</p> <p>$ entry = evdE (",", TRIM ($ Entries [$ I]));</p> <p>IF (($ Entry [0]! = GetENV ('Remote_addr') && ($ Entry [1]> Time ())) {</p> <p>Array_push ($ TEMP, $ Entry [0]. "," $ entry [1]. "/ n"); // Remove other viewers' information, and remove timeout, save to $ TEMP</p> <p>}</p> <p>}</p> <p>Array_push ($ TEMP, GETENV ('Remote_addr'). "," ($ TIMEOUT)). "/ n"); // Update the viewer's time</p> <p>$ USERS_ONLINE = Count ($ TEMP); // Calculate the number of online people</p> <p>$ entries = iMPLode ("", $ TEMP);</p> <p>// Write file</p> <p>$ fp = fopen ($ online_log, "w");</p> <p>FLOCK ($ fp, lock_ex); // flock () cannot work properly in NFS and some other network file systems</p> <p>FPUTS ($ FP, $ entries);</p> <p>FLOCK ($ fp, lock_un);</p> <p>Fclose ($ fp);</p> <p>Echo "currently there". $ usrs_online. "People Online";</p> <p>?></p> <p>Example 2:</p> <p>Implement online users with databases</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><?</p> <p>#</p> <p># Author: Marco (HKFUK)</p> <p>#</p> <p># Contact: [email] Crazy_marco@msn.com [/ email]</p> <p>#</p> <p>$ host = "localhost"; // mysql Host</p> <p>$ user = "root"; // mysql user name</p> <p>$ PW = ""; // mysql password</p> <p>$ db = ""; // mysql database name</p> <p>$ update_time = "30"; // Update frequency - second number session_start ();</p> <p>IF (! $ _ session ['name']) session_register ("name");</p> <p>#############################################################</p> <p>$ con = mysql_connect ($ Host, $ USER, $ PW) OR DIE ("No Database");</p> <p>$ now = Time ();</p> <p>Mysql_select_db ($ DB, $ Con) or Die ("Error Database $ DB");</p> <p>IF (! Empty ($ name)) {// If the user has already logged in</p> <p>$ query = mysql_query ("SELECT Count (username) from online_list where username = '$ name'", $ con); // Query whether online to the table already has the name of the user</p> <p>$ result = mysql_result ($ query, 0); // Query results</p> <p>IF ($ Result! = 0) {// If the user is already in the list</p> <p>@MYSQL_QUERY ("Update online_list set second_time = '$ now' where username = '$ name'", $ con); // Update the user's last online time</p> <p>} else {// If the user is already online list</p> <p>@MYSQL_QUERY ("INSERT INTO online_list (username, userip, online_time, second_time) VALUES ('$ Name', '$ Remote_addr', '$ now', '$ now')", $ con); // Add a user To the list</p> <p>}</p> <p>}</p> <p>ELSE {// If the user does not log in</p> <p>$ query = mysql_query ("SELECT Count (userip) from online_list where userip = '$ remote_addr'", $ con); // Query whether the online to the table has IP address</p> <p>$ result = mysql_result ($ query, 0); // Query results</p> <p>IF ($ Result! = 0) {// If the visitor's IP address is already online list</p> <p>@MYSQL_QUERY ("Update online_list set second_time = '$ now' where userip = '$ remote_addr', $ con); // Update the last online time of visitors</p> <p>} Else {// If the user list does not have a visitors of the IP address</p> <p>@Mysql_Query ("INSERT INTO online_list (username, userip, online_time, second_time) Values ​​('Visitor', '$ Remote_addr', '$ now', '$ now')", $ con); // Add a visit to List of online listings</p> <p>}</p> <p>}</p> <p>$ DEL_TIME = $ now- $ update_time;</p> <p>@MYSQL_QUERY ("Delete from online_list where second_time <$ del_time", $ con); // Delete users who do not have actions in $ UPDATE_TIME</p> <p>?></p> <p>29: What is template, how to use</p> <p>Here are a few articles about templates</p> <p>I use a phplib template</p> <p>Below is the use of several functions</p> <p>$ T-> Set_file ("Casual Definition", "Template file .tpl"); $ t-> set_block ("in set_file", "<! - From Template ->", "Casual Definition") ;</p> <p>$ T-> PARSE ("Defined in Set_Block", "" From Template -> ", TRUE);</p> <p>$ T-> PARSE ("Casual Output", "Defined in Set_File");</p> <p>Setting the loop format is:</p> <p><! - (more than one space) Begin $ handle (more than one space) -></p> <p>How to generate a template to a static page</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>// Use phpo templates</p> <p>..........</p> <p>..........</p> <p>$ TPL-> PARSE ("Output", "HTML");</p> <p>$ output = $ tpl-> get ("output"); // $ OUTPUT for the entire web content</p> <p>Function WFile ($ FILE, $ Content, $ mode = 'w') {</p> <p>$ oldmask = umask (0);</p> <p>$ fp = fopen ($ FILE, $ MODE);</p> <p>IF (! $ fp) Return False;</p> <p>FWRITE ($ FP, $ Content);</p> <p>Fclose ($ fp);</p> <p>Umask; $ oldmask;</p> <p>Return True;</p> <p>}</p> <p>// Write to the file</p> <p>WFILE ($ FILE, $ OUTPUT);</p> <p>Header ("Location: $ file"); / / redirection to the generated web page</p> <p>}</p> <p>?></p> <p>30: How to explain characters in PHP</p> <p>For example: input 2 2 * (1 2), automatically output 8</p> <p>Eval function can be used</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><form method = post action = ">"></p> <p><Input Type = "text" name = "str"> <input type = "submit"></p> <p></ form></p> <p><? PHP</p> <p>$ STR = $ _ post ['str'];</p> <p>EVAL ("/ $ o = $ str;");</p> <p>Echo "$ O";</p> <p>?></p> <p>In addition, use this function must be particularly careful!!</p> <p>If someone enters Format: D: What is the result?</p> <p>10: How to compare two dates a few days, (simpler algorithm)</p> <p>CODE:</p> <p>[Copy to CLIPBOARD]</p> <p><? PHP</p> <p>$ DATE_1 = "2003-7-15"; // can also be: $ DATE_1 = "2003-7-15 23:29:14";</p> <p>$ DATE_2 = "1982-10-1";</p> <p>$ D1 = STRTOTIME ($ DATE_1);</p> <p>$ D2 = STRTOTIME ($ DATE_2);</p> <p>$ Days = ROUND (($ D1- $ D2) / 3600/24);</p> <p>Echo "I have already struggled $ days day ^ _ ^";</p> <p>?></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-42048.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="42048" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.049</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '_2F9C3e6_2BRPjPRyoJlm7iqTZLUsftBQGhGAleyjoxtL_2F87RrJljQUGfd1jq1WJLRPymjQm6IdxK6B9DMtdC6W_2FlQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>