Lecture 4 on setting up a PHP personal website

WBOY
Release: 2016-07-29 08:33:51
Original
1045 people have browsed it

3. Home page news release, making updates easier for you (Part 2)
-----In the previous lecture, we have implemented the basic function of home page news release. In this lecture, we will add some bricks and mortar to it to make it more powerful. (A useful software is actually basic functions plus a number of auxiliary functions. These auxiliary functions are mainly for convenience, haha)
-----First of all, let's clarify what convenience we want to obtain. We don’t want to forget to delete something from dozens of days ago, and the result is still published as news on the homepage (very embarrassing ^&^). If we embed a piece of code in the basic implementation, for example using filectime($filename), then under UNIX we can get the time in seconds from January 1, 1970 to the last time the file was modified (in WINDOWS The following returns the date and time when the file was generated), and the number of seconds in seconds from January 1, 1970 to the present can be obtained using $mynow=mktime(), subtraction, judgment, IF > the time we expect , Hehe, Sorry, unlink($newspath.$filename)...what? ! Where should this code be placed, you ask? What do you think, haha.
Perhaps, you don’t often surf the Internet on the same machine. What should you do when you get a new piece of news but are not next to your favorite machine? The ideal thing is to upload files on the homepage. You may have a page (Admin?) that requires a password to enter (if you still cherish your website, this is necessary, it is best not to let others know the file name, haha). The following is a code for file uploading that can be seen everywhere:
if(isset($upfile))
{
?>
The uploaded file information is as follows:
File storage path :
Original file name :
File size (bytes):
File type :
}
else
{
?>

News upload



Please select or enter the upload file name:



}
?>
-----Here we see another form of combining PHP and HTML, which we can learn from. Although file uploading is convenient, it always gives people a sense of insecurity. Once the secret is leaked, the system security of your server will be threatened, because the uploaded files may be some destructive executable files (that is, viruses or hacker programs). A safe approach is to write a file that can be edited online. Here is an example :
〈? php
function mywritefile($filename,$contents){
if($fp=fopen($filename,"w")){
fwrite($fp,strpslashes($contents));
fclose($fp);
return 1;
}
else {return 0;};
};
//Determine the variables returned by the form
if($submitButton=="Complete"){
$rs=mywritefile("$page","$test ");
echo "$page
";
}
elseif($action=="page") //The value of variable action is "page "Situation
{$c
$fp=@fopen($content,"w+")or die('Could not open file!');
$c
fclose($fp);
echo "
";
echo "$contents";
echo "";
echo "";
echo "
";
}
else
{echo "
";//Pay attention to the way to reference variables in the program.
echo "";
echo "";
echo "";
}
?>
-----At this point, the implementation of home page news release has come to an end. We can find that any powerful Chen program is composed of some simple functions.The entire improvement process of the third part of the function uses the method of overlay enhancement, which is different from the top-down, layer-by-layer analysis development method of software engineering. This is a method suitable for learning. It is quite useful to write your own exercises, haha.

The above has introduced the fourth series of lectures on setting up a PHP personal website, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!