First, the basic structure of PHP:
Using the Include function
<title>Your page Subject and domain name</title>
The above content is the title of each page we use, do not move.
Head of each page:
"" Your others meta tag
"" Your others meta tag
"" Your others meta tag
"" Your others meta tag
"" Your others meta tag
"" Your others meta tag
"" Your others meta tag
Important JavaScripts code put this
CSS settings put this
The above content is saved as header.php so that each page has the same head.
All the content of your page
Save As footer.php so that the bottom of each page is the same.
Fill in our Copyright information
Two: How to output text or connect text to PHP
How do I display text in PHP? Use the following command:
How do I create a connection?
How do I create a connection with a style?
";? >
"echo" is used to display the output.
Three: How to realize paging:
If there's a lot of content on your page then we'll consider using paging as a way to implement the display.
A simple paging code:
<title>Webjx.com</title>
Home
Page 1
Page 2
|
Function index () { echo "
Welcome to this tutorial Here you can find funny Tricks
"; } $choice=$_get[' P '];Switch ($choice) { Case "Page1": echo " Page1 text, IMG and so on here "; BreakCase "Page2": echo " Page2 text, IMG and so on here "; BreakDefault Index (); } ?>
|
The above file must be saved as index.php
High-level paging code:
<title>Webjx.com</title>
Home
Page 1
Page 2
|
if (Isset ($_get[' action '))) $page = $_get[' action ']; else $page = ' home '; Switch ($page) { 1-index Case ' home ': Include (' incl/home.php '); Break 2-contact form Case ' Contact_us ': Include (' incl/contact_us.php '); Break 3-link US Case ' Link_us ': Include (' incl/link_us.php '); Break Default Echo ' Error 404! The page you request doesn t exist or as been temporarely unaccessible '; Break }?>
|
Provide the download of the demo, please try it yourself!
Four: Page load time code:
Echo ("page Took:");
$load = Microtime ();
Print (Number_format ($load,2));
Echo ("Sec to Load.");
?>
Five: Shows the code from which address goes to the station you are currently visiting:
echo "You Came from:
";
echo $_server[' Http_referer '];
?>
Six: Set the IP address of the turn: shielded IP
if (($remote_addr = = "22.22.22.22")://IP Address
print " ";//URL to redicted
endif
?>
Seven: The code for the title appears:
<?php include ("title.php");? >
To make a title.php file beforehand.
Eight; How to use PHP to create an HTML table
echo "\ n";
echo "\ n";
EchoAllo\ n ";
echo "\ n";
echo "bgcolor=\" #ffffff \ ">\n";
Echo
\ n ";
Echo
\ n "; Echo
\ n "; Echo
\ n "; Echo\ n "; Echo \ n "; echo "Text Goes here\n"; Echo \ n "; Echo | \ n "; Echo
\ n "; Echo
\ n ";
Echo ";
Echo\ n ";
Echo";
?>
Ix. declaring a String variable:
Create a page (config.php) to paste the following code:
$name= "Name";
$salutation= "hey!";
$title= "webjx.com";
$copyrights= "©2005 webjx.com";
$link_1= "Home";
?>
Create a page (test.php) put the following code
Placed inBefore, and then in the Test.php page to invoke the above string
It is also possible to declare:
$surname1= "Marco"; $lastname1= "Charette";
?>
Call:
X. Display information about your server:
11: Implement the page jump:
Create a "jump.php" page and set a variable to hide the connected address
if ($id = = "1") {$link = "http://webjx.com";}
if ($id = = "2") {$link = "http://google.com";}
Header ("Location: $link"); To achieve a jump
Exit ();
?>
After saving, add the following code to another page:
Visit this Link
Jump and also save the visitor to your page:
if ($id = = "1") {$link = "http://webjx.com";}
if ($id = = "2") {$link = "http://google.com";}
echo "\ n";
echo "\ n";
echo "\ n";
echo "\ n";
Header ("Location: $link");
Exit ();
?>
Save As jump.php and then join the connection code in the other pages:
Visit this Link
12. Protection page:
if (!STRCHR ($referer, "http://webjx.com/page.php")) {
echo "";
Exit (); }?>
13: Restrict access to a page
Choose a user name and password between the "" symbol
//===========================
$admin_user_name= "admin"; Your admin username
$admin_password= "Pass"; Your password
$site_com= "webjx.com"; Your website name without HTTP//and www
$login= "You have landed"; Succesful message when user is logged in (not necessary)
//===========================
Do not EDIT nothing below!
if ((!isset ($php_auth_user)) | | (!isset ($PHP_AUTH_PW))) {
/* No values:send Headers causing dialog box to appear */
Header (' Www-authenticate:basic realm= ' $site_com ');
Header (' http/1.0 401 Unauthorized ');
Echo '
Access to the page is restricted.
Please check your user name or password is correct, the normal landing site to view the contents of this site ';
Exit
} else if ((Isset ($php_auth_user)) && (Isset ($PHP_AUTH_PW))) {
/* values contain some values, so check to see if they ' re correct */
if (($php_auth_user! = "$admin_user_name") | | ($PHP_AUTH_PW! = "$admin_password")) {/* If either the username entered is incorrect, or the password entered is incorrect, send the headers causing dialog bo X to appear */
Header (' Www-authenticate:basic realm= ' $site_com ');
Header (' http/1.0 401 Unauthorized ');
Echo '
Access to the page is restricted.
Please check your user name or password is correct, the normal landing site to view the contents of this site ';
Exit
} else if (($php_auth_user = = "$admin_user_name") | | ($PHP_AUTH_PW = = "$admin_password")) {echo "$login
";
}
}
?>
Save As log.php and add the following code to the Head page, then all pages will be protected.
14. Make an automatic steering:
Header ("refresh:0; Url=http://webjx.com ");
?>
It must be saved as a PHP file.
xv To create a user list:
$customer[0] = ' WEBJX ';
$CUSTOMER[1] = ' web ';
$CUSTOMER[2] = ' Mutou ';
$CUSTOMER[3] = ' chuxia ';
$CUSTOMER[4] = ' Shenhua ';
echo "3rd User is: $customer[2]";
echo "
All the users:
";
= 5;
$x = 0;
while ($x < +) {
$customernumber = $x + 0;
echo "Costumer Name $customernumber is $customer[$x]
";
++$x;
}
?>
will be displayed:
The third customer is Mutou
All the users:
Costumer Name 0 is WEBJX
Costumer Name 1 is web
Costumer Name 2 is Mutou
Costumer Name 3 is Chuxia
Costumer Name 4 is Shenhua
Another way to read an array:
echo "3 of my Customer is: $customer[0],". "$customer[1] and". "$customer[2].". "
";
?>
will be displayed:
3 of my customer ARE:WEBJX, Web and Mutou.
16. Count the number of files in a directory:
Echo ("there is");
$dir = "/path/to/the/folder/in/your/computer";
$count = 0;
$handle=opendir ($dir);
while (($file = Readdir ($handle))!== false) {if ($file! = "." && $file! = "...") {$count++;}}
Echo $count;
Echo ("Pages for the Search in this Directory.");
?>
17. Displays the date of the current date or the latest update:
Show Update Date:
18. Repeat the code more than one character at a time:
Echo str_repeat ("-", 30);
?>
This article transfer from the station to learn http://www.jzxue.com, reproduced please indicate the source.