SoFunction
Updated on 2025-04-09

15 hours -- from modifying the program to your own programs



This article is original by a man who was blown down by the wind and has the copyright. From the forum, please keep this information when reprinting online. Please contact me if you reprint it on the Internet. It is not easy for an individual webmaster to write things by himself, and in order to give me the courage and motivation to continue writing, please do not delete this description when reprinting. This article is the first article, and I will find time to write down the future things one after another.


Many friends have long been obsessed with modifying other people's programs, and they are lazy and progressive because they can modify them. Or when they buy books to read, they find that the functions of php are extremely invincible, and they are scared to death when they see the function library. And so on. I myself belong to the latter. This article is specifically for lazy people who spend time learning php but want to do something by themselves.

Later, I participated in a minor in the school. The teacher taught in class and had to take the final exam, so I was forced to write simple code by myself.

Therefore, this article is aimed at friends who can modify html in program programs but cannot modify program structures. They have a basic program foundation, that is, they can understand if and else. It is enough, or people with the same foundation are suitable for everyone. Experts can go away. Until now, I still need to check the manual when using commonly used functions and still write spam code.

Okay, let’s talk nonsense, let’s enter the first stage

        
Friends who can modify programs are all web masters in the eyes of classmates. If I start with what variables are, it will inevitably delay your time. I am a text collection myself, so we can start by a detailed analysis of part of a program. The program is very simple, with only a few simple judgments, and I will write the program description in an invincible detail.

Quote: If you don't understand where you see, please tell me, I will modify it as soon as possible, or email me, my email address is rainboy#, please do not send me spam, I am already very annoyed by spam now
Let's start by analyzing the simplest counter

The function of the counter is: refresh the page once and increase the number by one.
The procedure is as follows

  Code: [Copy to clipboard]   <?
$datafile="";
$fp1=fopen($datafile,"r");
$num=fgets($fp1,10);
$num=trim($num);
fclose($fp1);
echo "You are the first".$num."Guest";
$fp2=fopen($datafile,"w");
$num=$num+1;
fputs($fp2,"$num");
fclose($fp2);
?>
Here is a detailed explanation of the program   Code: [Copy to clipboard]   <?

/* php files are all wrapped in <? ?> or <?php ?>. When the server executes, the contents in the tag can be removed to execute.*/

/*
Set the data storage file, because the variables in php are stored in the server memory and disappear immediately after execution, so we need to use text to save the number of visitors to browse. After we use this, we can adjust it according to the situation. The variables in php are preceded by a $ symbol, so those with $ symbols are all variables. Create the data file manually, write 1 in it, and then save it.
*/
$datafile="";


/*This step is to open the file, using the fopen() function. The fopen function is the function to open the file. The function accepts two parameters, one is the file name and the other is the opening method. For example, this program uses the "r" method to open it here, which is read-only. $fp1 is a handle, what is a handle? Just like when you use a toothbrush, you use the handle of the toothbrush to clean your teeth. Then $fp1 is like that toothbrush handle. PHP operates the handle of the $fp1 to control the data storage file. This step is summarized in one sentence: use the fopen function to open the data file and pass the handle of the opened file to $fp1. If you still have questions about the use of the fopen function, please refer to the php online manual/manual/
How to use fopen function
*/
$fp1=fopen($datafile,"r");


/*
To summarize the use of this statement in one sentence: Open the file and read the data
Use the function: fgets("handle", "number of bytes to read the file content");, the result is to read the handle $fp1 to achieve the purpose of reading the file content. This sentence obtains $num, which is the first 10 bytes in the file.
*/
$num=fgets($fp1,10);


/*
The trim(); function is used to remove the spaces before and after a string, for example
$num="123          ";
trim($num) is 123;
*/
$num=trim($num);

/*
The fclose function closes the file. The parameter required by the fclose function is $fp1
*/
fclose($fp1);

/*

Everyone knows how to use echo functions, which is equivalent to print(); the meaning of output on the web page
Use "." between the connection string and variable, so that variables can be printed in php. The use of the connection symbol "." is very important. To be clear, please refer to the php online manual/manual/ of this website
The part about string concatenation.
*/
echo "You are the first".$num."Guest";


/*
Use fopen to open the file. The opening method is "w". The file opened for the w method is in write-only mode. If the file does not exist, create the file. If the file exists, clear the file contents first. Then write it. The purpose of this sentence is to open the file and pass the handle to $fp2.
*/
$fp2=fopen($datafile,"w");

/*The number of views increased by one*/
$num=$num+1;

/*The usage method of writing a number after adding one to the file fputs is very simple. The first parameter is the file handle, and the second parameter is the content to be written. If you have any doubts about the usage method of the fputs function, please refer to /manual/*/ in the php online manual of this website
fputs($fp2,"$num");

/*Close open file*/
fclose($fp2);
?>

(Source:)