PHP personal website construction overview

Source: Internet
Author: User
Tags newsfile
Here, I would like to share with you my personal website construction experience. Sorry, please correct me! Is it cool to edit and debug win98 locally? First, run OmnihttpdProffesinalV2.06 and install PHP4beta3. If you know HTML better, EditPlus is recommended! Otherwise, you have to use DreamWeaver first. You also need to connect to the database's personal website

Here, I would like to share with you my personal website construction experience. Sorry, please correct me!
1. edit the debugging environment
Win98 local editing and debugging, cool? First, run Omnihttpd Proffesinal V2.06 and install PHP4beta3. If you know HTML better, EditPlus is recommended! Otherwise, you have to use DreamWeaver first. Connect to the database? Fortunately, MySQL also has the For WIN32 version.
2. first, a counter
Your counters are always better than others! The counter source code introduced today is always the kind of refresh that will take a long time, so it is a bit self-deceiving. However, let's analyze how it works first. Below is an example of a simple counter:
   If (file_exists ($ countfile ))
{$ Fp = fopen ($ countfile, "r ");
$ Count = fgets ($ fp, 5); $ count = 1; rewind ($ fp );
Fputs ($ fp, $ count, 5 );
Fclose ($ fp );
}
Else
{
$ Fp = fopen ($ countfile, "w ");

$ Count = "1 ";

Fputs ($ fp, $ count, 5 );

Fclose ($ fp );

};

?>

This counter has an external number, which is called "long _ ^" when it is flushed. So how can we make the counter more authentic? PHP4 gives us a simple way to use SESSION-level variables. When you enter the page, first check whether the COUNT in the SESSION exists and is equal to the value you want. Otherwise, the COUNT is equal to the first, and then call the COUNT process. after the SESSION ends, you can say to COUNT: byeBye!

But what should I do if it is not PHP4? Do you still remember the cookie? We can assume that a person's request to your web page does not belong to a new user within 15 minutes (or within another period of time), so that you can make a counting process in INC, when each page is referenced, the visitor sends the access time to the cookie upon first entry. When each page is accessed, the last cookie access time value will be checked. If the difference is greater than 15 minutes, it will be counted; otherwise, the time will be refreshed. (You don't even know how to use cookies, do you? Haha, we recommend a book "PHP core programming", which is in Tsinghua version. it is enough to query functions. every function has an example:-D)

However, the counter just now has no appearance at all. it is estimated that you are not satisfied. change the image. Make a set of 0.jpg, 1.jpg ...... 9. jpg. Didn't I just read a string? After the combined outputs, the graphic counter will not come out?

Well, the counters for individual users are already perfect.

Three homepage news publishing makes it easier for you to update (on)
-------- Each time you add a message to the homepage and add two sentences, you have to upload the entire page. this is really not worth it! As a result, lazy people like Lanfeng have come up with a permanent solution to implement dynamic real-time, remote management and editing, and automatic maintenance. It can also be used as a bulletin board for virtual communities. (If you change it, you can automatically generate a feed for your news center on the homepage .) Forgive me for all these features.
-------- Insert a few digress first. when we build a website, do we use html to embellish PHP in the middle or use PHP to generate html? Professional websites can centralize a function on one page and call different modules to implement each sub-function. (does the client have only one page? I have not tried ). In any case, Software Reuse with modular functions is an important method for efficient development (it can also save your host space ).
-------- Okay. let's modularize the functions. For beginners, read the code carefully and pay special attention to the usage of basic functions. Experts can skip this section, huh, huh (so seriously? I am so sorry -().
   /* Head. php to avoid being directly typed in head by others. inc downloads your source code. it is best to use php as the suffix so that your server will first intercept it for processing */
Echo""<BR> echo" "// if the title changes frequently, you can create a function. <BR> echo""
?>
This is a functional block for writing html headers.
   /* Makestr. php defines a function that processes hyperlinks in the public text, assuming the link form in the text is $ {http://www.yoyonow.net | network management path }*/
Function makestr ($ text)
{$ Str = $ text;
$ A = strstr ($ s, '$}'); // remove the substring before '$ {' in $ s.
If ($ ){
$ B = strstr ($ ,'}');
If ($ B ){
$ La = strlen ($ a); $ ls = strlen ($ s); // Obtain the string length
$ S = substr ($ a, 0, $ ls-$ la); // Obtain the substring. The second parameter is the starting point, and the third parameter is the number of characters.
$ A = substr ($ a, 2); // Remove '$ {'
$ Lb = strlen ($ B); $ la = strlen ($ );
$ A = substr ($ a, 0, $ la-$ lb); // Retrieve the hyperlink
$ B = substr ($ B, 1); // Remove '}'
$ Ta = strstr ($ a, "|"); // you can specify whether the link text exists.
If ($ ta ){
$ La = strlen ($ a); $ lt = (strlen ($ ta );
$ Linktext = substr ($ a, $ la-$ lt 1 );
$ A = substr ($ a, 0, $ la-$ lt );
}
Else {
$ Linktext = $;
}
$ S = $ s. ". $ linktext.". $ B; // prepare the returned string.
}
}
Return ($ s );
}

-------- If you are a newbie, you should look for an html getting started book. Otherwise, it is difficult to become a PHP Master. These functions that you start to look very simple and process strings. after your clever use, you can do a lot of beautiful things. In the next lecture, we can see the results we have prepared for a long time.

Three homepage news publishing makes it easier for you to update (medium)

We made a file header last time (as for the end of the file, please do it yourself, assuming it is tail. php), a function module. now, let's implement a basic function, that is, dynamic release.

   Include ("makestr. php ";
Include ("head. php ");
$ Newspath = "/announce/"; // News file directory stored in text files
$ Newsfile = array (); // prepare a News array
$ Hd = dir ($ newspath); // Directory handle
While ($ filename = $ hd-> read () {// get all files
$ S = strtolower ($ filename );
If (strstr ($ s, ". txt ")){
// Check the latest modification date
$ Lastchanged = fileatime ($ newspath. $ filename );
$ Newsfile [$ filename] = $ lastchanged;
}
}
Arsort ($ newsfile); // sort files by time
// Output file
For (reset ($ newsfile); $ key = key ($ newsfile); next ($ newsfile ))
{$ Fa = file ($ newspath. $ key );
$ N = count ($ fa );
Echo"

". Date (" d. m. Y-H: I: s ". $ newsfile [$ key])."
\ N ";
For ($ I = 0; $ I <$ n; $ I = $ I 1 ){
$ S = chop ($ fa [$ I]); // remove spaces
$ S = htmlspecialchars ($ s );
Print $ s ."

\ N ";

}
}
$ Hd-> close (); // release the handle
Include ("tail. php ");
?>
In this way, you can easily publish news by uploading your news text to the annouce subdirectory in your root directory. But the real convenience is not here. For example, when the news is outdated, the program can automatically delete it. It is convenient to directly write new announcements online without using ftp. Now, let's listen to the next decomposition.

Three homepage news publishing makes it easier for you to update (below)

----- In the previous lecture, we have implemented the basic functions of homepage news publishing. In this lecture, we will add more bricks and tiles to make it more powerful. (An easy-to-use software, in fact, is the addition of a batch of ancillary functions of basic functions. these ancillary functions are also easy to figure)
----- First, let's clarify what convenience we want. We don't want to forget to delete things that we did a few days ago. The results are also published on the homepage as news (shame! ^ & ^ ). If we embed a piece of code in the basic implementation, such as using filectime ($ filename), then in UNIX, we can get the time from January 1, January 1, 1970 to the time when the last File was modified (the date and time when the file was generated in WINDOWS ), from January 1, January 1, 1970 to the current number of seconds, you can use $ mynow = mktime () to get, subtract, and Judge. IF> the expected time, Hey, Sorry, unlink ($ newspath. $ filename )...... What ?! Where should I put this code? What do you mean.
Maybe you are not always surfing the Internet on a machine. what should you do if you get a new news but are not on your computer? The most ideal thing is to upload files on the home page. You may have a page (Admin ?) You must use a password to access the website. (if you still cherish your website, this is necessary. you 'd better not let others know the file name ). The following code uploads a file that is everywhere:
   If (isset ($ upfile ))
{
?>

The information of uploaded files is as follows:
File storage path:
Original file name:
File size (in bytes ):
File type:

   }
Else
{
?>
  
  News uploading
  
  
   }
?>

----- Here we see a combination of PHP and HTML for reference. Although it is convenient to upload files, it always gives a sense of insecurity. Once leaked, the system security of your server is threatened, because the uploaded files may be some destructive execution files (that is, viruses or hacker programs) it is safe to write an online edited file. The following is an example:

<〈? Php
Function mywritefile ($ filename, $ contents ){
If ($ fp = fopen ($ filename, "w ")){
Fwrite ($ fp, strpslashes ($ contents ));
Fclose ($ fp );
Return 1;
}
Else {return 0 ;};
};
// Judge the variables returned by the form
If ($ submitButton = "finished "){
$ 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 "";
}
Else
{Echo "";
}
?>

----- Now, the implementation of homepage news publishing has come to an end. We can find that any powerful statement is composed of some simple functions. The third part of the entire functional improvement process uses the method of superposition enhancement, and the software engineering top-down, layer-by-layer analysis development method is different. This is a method suitable for learning. it is quite useful to write your own exercises.

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.