欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【新手入门:初学动态网页PHP的18个例子】,下面是详细的分享!
新手入门:初学动态网页PHP的18个例子
如何创建我们的第一个PHP页面呢?非常简单的!选择我们使用的一个最好的设计工具,当然你也可以 只使用记事本。创建之后记得要保存为扩展名为PHP的文件,然后传到我们的服务器上。
在编写PHP程序之前通常我们需要配置我们的环境,也就是说服务器要支持PHP才能行啊
一、PHP的基本结构:
使用Include函数
| 以下为引用的内容: <Html> <Head> <title>Your page Subject and domain name</title> |
上面内容为我们使用的每个页面的标题,不要动。
每个页的头部:
| 以下为引用的内容: <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设置放这
上述内容保存为header.php,使每个页面的头部都是一样的。
| 以下为引用的内容: <?PHP include("header.php")?> </head> |
你的页的所有内容
| 以下为引用的内容: </body> </html> |
保存为footer.php,使每个页面的底部都一样。
<? include("footer.php");?>
填写我们的版权信息
| 以下为引用的内容: </body> </html> |
二、如何输出文本或者把文本建立连接用PHP
在PHP中如何显示文本呢?使用下面的命令:
<?php echo "Hello in php";?>
如何创建一个连接呢?
<?php echo "<a href=http://www.chinaz.com/program/2007/0824/\"http://www.webjx.com\">www.webjx.com.com</a>";?>
如何创建一个有style的连接呢?
<?php echo "<font style=\"color:blue;font-size:10px;font- family:verdana;\">Free Scripts By: <a href=http://www.chinaz.com/program/2007/0824/\"http://www.webjx.com.com\" target=\"_blank\" title=\"Free Scripts By: webjx.com\">http://www.webjx.com</font></a>";?>
"echo"是用来显示输出的。
三、如何实现分页
如果好多内容在你的页面中这时我们就考虑用分页形式来实现显示了。
简单的分页代码:
| 以下为引用的内容: <html> switch($choice) echo "<p align=center>Page1 text, img and so on here</p>"; case "Page2": echo "<p align=center>Page2 text, img and so on here</p>"; default: ?> </p> 以上文件必须保存为index.php 高级分页的代码: <html> if (isset($_GET['action'])) $PAGE=$_GET['action']; else $PAGE='home'; //2-contact form ?> </p> |
提供了演示的下载,请自己去试试!
四、页面加载时间的代码
| 以下为引用的内容: <?php echo ("Page Took :"); ?> |
五、显示从哪个地址转到你当前访问的站的代码
| 以下为引用的内容: <?php echo "You Came From:<br />"; |
六、设置IP地址的转向:屏蔽IP
| 以下为引用的内容: <?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 |
七、随即显示标题的代码
<Title><?php include("title.php");?></Title>
要事先做一个title.php文件啊
八、如何用PHP来建立一个HTML 的table
| 以下为引用的内容: <?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>"; ?> |
九、声明字符串变量
建立一个页面 ( config.php ) 粘贴下面代码
| 以下为引用的内容: <? $name="Name"; $salutation="Hey!"; $title="webjx.com"; $copyrights="©2005 webjx.com"; $link_1="Home"; ?> |
创建一个页面( test.php )把下列代码
<? include("config.php");?>
放在<html><head>之前,然后在test.php页里来调用上面的字符串
<p align="center"><? echo("$title");?></p>
也可以这样来声明:
| 以下为引用的内容: <? $surname1="Marco"; $lastname1="Charette"; ?> |
调用:
<? echo("$surname1 $lastname1");?>
十、显示你的服务器的信息:
<? phpinfo(); ?>
十一、实现页面的跳转:
创建"jump.php"页面并且设置变量来隐藏连接的地址
| 以下为引用的内容: <? header("Location: $link"); // 实现了跳转 |
保存之后,在另外一个页中加入如下代码:
<a href=http://www.chinaz.com/program/2007/0824/"jump.php?id=1">Visit This Link</a>
跳转并且还把访客保存在你的页面内:
| 以下为引用的内容: <? echo "<frameset rows=\"0,100%\" border=\"0\">\n"; header("Location: $link"); |
保存为jump.php然后再其他页内加入连接代码:
<a href=http://www.chinaz.com/program/2007/0824/"jump.php?id=1">Visit This Link</a>
十二、保护页面
| 以下为引用的内容: <? $Referer=getenv("HTTP_REFERER"); if (!strchr($Referer, "http://webjx.com/page.php")) { echo "<script>alert('你不能访问这个页面'); window.location='http://webjx.com';</script>"; exit(); } ?> |
十三、限制访问某个页面
| 以下为引用的内容: // choose a user name and password between the " " symbol // DO NOT EDIT NOTHING BELOW! if ((!isset($PHP_AUTH_USER)) || (!isset($PHP_AUTH_PW))) { header('WWW-Authenticate: Basic realm="$site_com"'); header('HTTP/1.0 401 Unauthorized'); echo '<h1>访问的页面被限制.</h1>请检查你的用户名或密码是否正确,正常登陆本站才能查看 本站的内容'; } else if ((isset($PHP_AUTH_USER)) && (isset($PHP_AUTH_PW))){ if (($PHP_AUTH_USER !="$admin_user_name") || ($PHP_AUTH_PW !="$admin_password")) { header('WWW-Authenticate: Basic realm="$site_com"'); ?> |
保存为log.php,把下列代码加到head页内,那么将会保护所有的页面。
<? require("log.php");?>
十四、制作一个自动转向
<?php
header("Refresh:0; url=http://webjx.com");
?>
必须保存为php文件才可以。
十五、制作用户列表
| 以下为引用的内容: <? echo "<br /><br />所有的用户:<br /><br />"; $number=5; 所有的用户: Costumer Name 0 is webjx |
另一种读取数组的方法:
| 以下为引用的内容: <? echo "3 of my customer are: $customer[0], " . " $customer[1] and " . " $customer[2]. " . "<br />"; ?> |
将会显示:
3 of my customer are: webjx, web and mutou.
十六、统计某个目录下文件的数量
| 以下为引用的内容: <? echo(" Pages For You To Search In This Directory."); |
十七、显示当前日期或最新更新的日期
<?php echo date("F d Y"); ?>
显示更新日期:
<?php echo "Last Modified: " . date ("m/d/y.", getlastmod());?>
十八、重复一个字符多次的代码
| 以下为引用的内容: <? |
以上所分享的是关于新手入门:初学动态网页PHP的18个例子,下面是编辑为你推荐的有价值的用户互动:
相关问题:我是一个DW的初学者想学习动态网页技术,不知道哪 ...
答:可以告诉你做网页的步骤 1,用ps设计出网页的基本版式,并填充内容 2,实用切片工具,将ps所做出来的那张大图片切成n个小图片,然后用DW实现超链接效果 3,后台编程。做网页脚本一般用jsp,asp,php,三种之一。 注:ps作出来的图片的格式为PSD格式... >>详细
相关问题:学习动态网站的一般步骤?
答:补充回答: 你想学 自己认清一个方向。目前比较流行的做网站开发的 是ASP.NET,JSP,PHP 这三种语言。 个人比较喜欢ASP.NET ,JSP我也学了 。虽然说PHP目前web开发应该说性能算最好的了。 但是毕竟是个非主流的产品,所以并不看好他的前景。 自学... >>详细
相关问题:做动态网页最好要用到什么技术啊?我是一个新手,...
答:首先你要清楚你想要做前台还是后台,前台的话就是:div + css,然后开始学习javaScript, jquery做特效,或者去学一些ps,如果是后台,那你先了解一下java ,.net,PHP等技术,然后选择一个去学习,最后在去学习一些深层次的技术 >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
