欧美日韩精品在线,国内精品久久久久久久久,一级毛片恃级毛片直播,清纯唯美亚洲综合欧美色

新手入門(mén):初學(xué)動(dòng)態(tài)網(wǎng)頁(yè)P(yáng)HP的18個(gè)例子_PHP教程

編輯Tag賺U幣
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

推薦:新手入門(mén):IIS6環(huán)境下的PHP最佳配置方法
雖然 LAMP 組合很不錯(cuò),但是如果想要架設(shè)一臺(tái)同時(shí)支持PHP、ASP、ASP.NET、JSP、Perl的Web虛擬主機(jī)服務(wù)器,還是用 Windows 2003的IIS 6最好。網(wǎng)上有很多介紹在IIS 6上配置PHP的文章,但是那些方

如何創(chuàng)建我們的第一個(gè)PHP頁(yè)面呢?非常簡(jiǎn)單的!選擇我們使用的一個(gè)最好的設(shè)計(jì)工具,當(dāng)然你也可以 只使用記事本。創(chuàng)建之后記得要保存為擴(kuò)展名為PHP的文件,然后傳到我們的服務(wù)器上。

在編寫(xiě)PHP程序之前通常我們需要配置我們的環(huán)境,也就是說(shuō)服務(wù)器要支持PHP才能行啊

一、PHP的基本結(jié)構(gòu):

使用Include函數(shù)

以下為引用的內(nèi)容:
<Html>
<Head>
<title>Your page Subject and domain name</title>

上面內(nèi)容為我們使用的每個(gè)頁(yè)面的標(biāo)題,不要?jiǎng)印?/p>

每個(gè)頁(yè)的頭部:

以下為引用的內(nèi)容:
<Meta NAME="" CONTENT="">
"" 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

重要的javascripts代碼放這

CSS設(shè)置放這

上述內(nèi)容保存為header.php,使每個(gè)頁(yè)面的頭部都是一樣的。

以下為引用的內(nèi)容:

<?PHP include("header.php")?>

</head>
<body>

你的頁(yè)的所有內(nèi)容

以下為引用的內(nèi)容:
</body>
</html>

保存為footer.php,使每個(gè)頁(yè)面的底部都一樣。

<? include("footer.php");?>

填寫(xiě)我們的版權(quán)信息

以下為引用的內(nèi)容:
</body>
</html>

二、如何輸出文本或者把文本建立連接用PHP

在PHP中如何顯示文本呢?使用下面的命令:

<?php echo "Hello in php";?>

如何創(chuàng)建一個(gè)連接呢?

<?php echo "<a href=\"http://m.dounai2.com\">m.dounai2.com.com</a>";?>

如何創(chuàng)建一個(gè)有style的連接呢?

<?php echo "<font style=\"color:blue;font-size:10px;font- family:verdana;\">Free Scripts By: <a href=\"http://m.dounai2.com.com\" target=\"_blank\" title=\"Free Scripts By: mb5u.com\">http://m.dounai2.com</font></a>";?>

"echo"是用來(lái)顯示輸出的。

三、如何實(shí)現(xiàn)分頁(yè)

如果好多內(nèi)容在你的頁(yè)面中這時(shí)我們就考慮用分頁(yè)形式來(lái)實(shí)現(xiàn)顯示了。

簡(jiǎn)單的分頁(yè)代碼:

以下為引用的內(nèi)容:

<html>
<head>
<title>mb5u.com</title>
</head>
<body text="#000000">
<center>
<table width="500" border="3">
<tr>
<td width="140" height="400" valign="top">
<p align="center">
<a href='index.php'>home</a><br />
<a href='index.php?p=Page1'>page 1</a><br />
<a href='index.php?p=Page2'>page 2</a><br />
</p></td>
<td width="360" height="400" valign="top">
<p>
<?
function index()
{
echo "<p align=center>Welcome to this tutorial<br />Here you can find funny
tricks</p><br /><br /><br /><br /><br /><br />"; }
$choice=$_GET['p'];

switch($choice)
{
case "Page1":

echo "<p align=center>Page1 text, img and so on here</p>";
break;

case "Page2":

echo "<p align=center>Page2 text, img and so on here</p>";
break;

default:
index();
}

?>

</p>
</td>
</tr>
</table> </center>
</body>
</html>

以上文件必須保存為index.php

高級(jí)分頁(yè)的代碼:

<html>
<head>
<title>mb5u.com</title>
</head>
<body text="#000000">
<center>
<table width="500" border="3">
<tr>
<td width="140" height="400" valign="top">
<p align="center">
<a href='index.php'>home</a><br />
<a href='index.php?action=contact_us'>page 1</a><br />
<a href='index.php?action=link_us'>page 2</a><br />
</p></td>
<td width="360" height="400" valign="top">
<p>
<?

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 '<p align=center>Error 404! the page you request doesn t exist or as been temporarely unaccessible</p>';
break;
}

?>

</p>
</td>
</tr>
</table>
</center>
</body>
</html>

提供了演示的下載,請(qǐng)自己去試試!

四、頁(yè)面加載時(shí)間的代碼

以下為引用的內(nèi)容:

<?php

echo ("Page Took :");
$load = microtime();
print (number_format($load,2));
echo (" Sec To Load.");

?>

五、顯示從哪個(gè)地址轉(zhuǎn)到你當(dāng)前訪問(wèn)的站的代碼

以下為引用的內(nèi)容:

<?php

echo "You Came From:<br />";
echo $_SERVER['HTTP_REFERER'];
?>

六、設(shè)置IP地址的轉(zhuǎn)向:屏蔽IP

以下為引用的內(nèi)容:

<?php

if(($REMOTE_ADDR == "22.22.22.22")):// ip address

print "<meta http-equiv='refresh' content='0; url=http://www.sina.com'>";// url to redicted
endif;
?>

七、隨即顯示標(biāo)題的代碼

<Title><?php include("title.php");?></Title>

要事先做一個(gè)title.php文件啊

八、如何用PHP來(lái)建立一個(gè)HTML 的table

以下為引用的內(nèi)容:
<?php
echo"<html>\n";
echo"<head>\n";
echo"<title>allo</TITLE>\n";
echo"</head>\n";
echo"<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"5\"
bgcolor=\"#ffffff\">\n";
echo"<center>\n";
echo"<table width=\"500\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo"<tr>\n";
echo"<td>\n";
echo"<p align=\"center\">\n";
echo"
\n";
echo"Text Goes Here\n";
echo"</p>\n";
echo"</td>\n";
echo"</tr>\n";
echo"</table>\n";
echo"</center>";
echo"</body>\n";
echo"</html>";
?>

九、聲明字符串變量

建立一個(gè)頁(yè)面 ( config.php ) 粘貼下面代碼

以下為引用的內(nèi)容:
<?
$name="Name";
$salutation="Hey!";
$title="mb5u.com";
$copyrights="©2005 mb5u.com";
$link_1="Home";
?>

創(chuàng)建一個(gè)頁(yè)面( test.php )把下列代碼

<? include("config.php");?>

放在<html><head>之前,然后在test.php頁(yè)里來(lái)調(diào)用上面的字符串

<p align="center"><? echo("$title");?></p>

也可以這樣來(lái)聲明:

以下為引用的內(nèi)容:
<?
$surname1="Marco"; $lastname1="Charette";
?>

調(diào)用:

<? echo("$surname1 $lastname1");?>

十、顯示你的服務(wù)器的信息:

<? phpinfo(); ?>

十一、實(shí)現(xiàn)頁(yè)面的跳轉(zhuǎn):

創(chuàng)建"jump.php"頁(yè)面并且設(shè)置變量來(lái)隱藏連接的地址

以下為引用的內(nèi)容:

<?
if ($id == "1"){$link = "http://mb5u.com";}
if ($id == "2"){$link = "http://google.com";}

header("Location: $link"); // 實(shí)現(xiàn)了跳轉(zhuǎn)
exit();
?>

保存之后,在另外一個(gè)頁(yè)中加入如下代碼:

<a href="jump.php?id=1">Visit This Link</a>

跳轉(zhuǎn)并且還把訪客保存在你的頁(yè)面內(nèi):

以下為引用的內(nèi)容:

<?
if ($id == "1"){$link = "http://mb5u.com";}
if ($id == "2"){$link = "http://google.com";}

echo "<frameset rows=\"0,100%\" border=\"0\">\n";
echo "<frame src=\"jump.php\" name=\"head\" scrolling=\"no\" marginheight=\"0\" frameborder=\"0\" noresize>\n";
echo "<frame src=\"$link\" name=\"body\" marginheight=\"10\" marginwidth=\"10\" frameborder=\"0\" noresize>\n";
echo "</frameset>\n";

header("Location: $link");
exit();
?>

保存為jump.php然后再其他頁(yè)內(nèi)加入連接代碼:

<a href="jump.php?id=1">Visit This Link</a>

十二、保護(hù)頁(yè)面

以下為引用的內(nèi)容:
<? $Referer = getenv("HTTP_REFERER");
if (!strchr($Referer, "http://mb5u.com/page.php")) {
echo "<script>alert('你不能訪問(wèn)這個(gè)頁(yè)面');
window.location='http://mb5u.com';</script>";
exit(); } ?>

十三、限制訪問(wèn)某個(gè)頁(yè)面

以下為引用的內(nèi)容:

// choose a user name and password between the " " symbol
//===========================
$admin_user_name="admin"; // your admin username
$admin_password="pass"; // your password
$site_com="mb5u.com"; // your website name WITHOUT http:// and www
$login="你已經(jīng)登陸"; // succesful message when user are 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 '<h1>訪問(wèn)的頁(yè)面被限制.</h1>請(qǐng)檢查你的用戶(hù)名或密碼是否正確,正常登陸本站才能查看 本站的內(nèi)容';
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 box to appear */

header('WWW-Authenticate: Basic realm="$site_com"');
header('HTTP/1.0 401 Unauthorized');
echo '<h1>訪問(wèn)的頁(yè)面被限制.</h1>請(qǐng)檢查你的用戶(hù)名或密碼是否正確,正常登陸本站才能查看 本站的內(nèi)容';
exit;
} else if (($PHP_AUTH_USER == "$admin_user_name") || ($PHP_AUTH_PW == "$admin_password")) { echo "$login<br />";
}
}

?>

保存為log.php,把下列代碼加到head頁(yè)內(nèi),那么將會(huì)保護(hù)所有的頁(yè)面。

<? require("log.php");?>

十四、制作一個(gè)自動(dòng)轉(zhuǎn)向

<?php

header("Refresh:0; url=http://mb5u.com");

?>

必須保存為php文件才可以。

十五、制作用戶(hù)列表

以下為引用的內(nèi)容:

<?
$customer[0] = 'mb5u';
$customer[1] = 'web';
$customer[2] = 'mutou';
$customer[3] = 'chuxia';
$customer[4] = 'shenhua';
echo "第3個(gè)用戶(hù)是: $customer[2]";

echo "<br /><br />所有的用戶(hù):<br /><br />";

$number = 5;
$x = 0;
while ($x < $number) {
$customernumber = $x 0;
echo "Costumer Name $customernumber is $customer[$x]<br />";
$x;
}
?>
將會(huì)顯示:
The third customer is mutou

所有的用戶(hù):

Costumer Name 0 is mb5u
Costumer Name 1 is web
Costumer Name 2 is mutou
Costumer Name 3 is chuxia
Costumer Name 4 is shenhua

另一種讀取數(shù)組的方法:

以下為引用的內(nèi)容:
<?
echo "3 of my customer are: $customer[0], " . " $customer[1] and " . " $customer[2]. " . "<br />";
?>

將會(huì)顯示:

3 of my customer are: mb5u, web and mutou.

十六、統(tǒng)計(jì)某個(gè)目錄下文件的數(shù)量

以下為引用的內(nèi)容:

<?
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 You To Search In This Directory.");
?>

十七、顯示當(dāng)前日期或最新更新的日期

<?php echo date("F d Y"); ?>

顯示更新日期:

<?php echo "Last Modified: " . date ("m/d/y.", getlastmod());?>

十八、重復(fù)一個(gè)字符多次的代碼

以下為引用的內(nèi)容:

<?
echo str_repeat("-", 30);
?>

分享:關(guān)于PHP字符集的問(wèn)題
字符集當(dāng)然有很多的種類(lèi),在中國(guó)大陸主要是使用GB2312的,但是有的時(shí)候我們還是應(yīng)該考慮一下國(guó)外的朋友訪問(wèn)你的網(wǎng)站的問(wèn)題,那么你就應(yīng)該使用UTF-8了,其實(shí)這個(gè)是一個(gè)趨勢(shì)吧,很多的國(guó)內(nèi)網(wǎng)站也

來(lái)源:模板無(wú)憂(yōu)//所屬分類(lèi):PHP教程/更新時(shí)間:2008-08-22
相關(guān)PHP教程