Home >Backend Development >PHP Tutorial >Lecture on setting up a PHP personal website (4)_PHP tutorial

Lecture on setting up a PHP personal website (4)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:04:09844browse

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.
Maybe 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 home page. 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 piece of file upload code 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 combination of PHP and HTML The form can be used as a reference. 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 variable returned by the form
if($submitButton= ="Complete"){
$rs=mywritefile("$page","$test");
echo "$page}
elseif($action=="page") //When the variable action value is "page"
{$contents="$page";
$fp=@ fopen($content,"w+")or die('Could not open file!');
$contents=htmlspecialchars($contents);
fclose($fp);
echo "
";
echo "$contents";
echo "";
echo "< ;input type="submit" name="submitButton" value="Complete">";
echo "
";
}
else
{echo "
";//Pay attention to the way variables in the program are referenced.
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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316019.htmlTechArticleThree homepage news releases, making it easier for you to update (Part 2) -----In the previous lecture, we The basic function of news release on the home page has been implemented. In this lecture, we will add more bricks and mortar to it to make...
Statement:
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