php基础代码,php代码加密
大家好,今天给各位分享php基础代码的一些知识,其中也会对php代码加密进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!
php基础知识点
php基础知识点
PHP是一种非常流行的开源服务器端脚本语言,下面我整理了php基础知识点,希望对大家有帮助!
定义和用法
strrev()函数反转字符串。
语法
strrev(string)
参数描述
string必需。规定要反转的字符串。
echo和print都可以做输出,不同的是,echo不是函数,没有返回值,而print是一个函数有返回值,所以相对而言如果只是输出 echo会更快,而print_r通常用于打印变量的相关信息,通常在调试中使用。
print是打印字符串
print_r则是打印复合类型如数组对象
$arr= array('a','b','c');
foreach($arr as&$v){}
print_r($arr);
结果:
Array( [0]=> a [1]=> b [2]=> c)
foreach($arr as$v){}
print_r($arr);
结果:
Array( [0]=> a [1]=> b [2]=> b)
HTTP请求
请求方法(所有方法全为大写)有多种,各个方法的解释如下:
GET请求获取Request-URI所标识的资源
POST在Request-URI所标识的资源后附加新的数据
HEAD请求获取由Request-URI所标识的资源的响应消息报头
PUT请求服务器存储一个资源,并用Request-URI作为其标识
DELETE请求服务器删除Request-URI所标识的资源
TRACE请求服务器回送收到的请求信息,主要用于测试或诊断
CONNECT保留将来使用
OPTIONS请求查询服务器的性能,或者查询与资源相关的选项和需求
HTTP响应也是由三个部分组成,分别是:状态行、消息报头、响应正文
1、状态行格式如下:
HTTP-Version Status-Code Reason-Phrase CRLF
其中,HTTP-Version表示服务器HTTP协议的版本;Status-Code表示服务器发回的响应状态代码;Reason-Phrase表示状态代码的`文本描述。
状态代码有三位数字组成,第一个数字定义了响应的类别,且有五种可能取值:
1xx:指示信息--表示请求已接收,继续处理
2xx:成功--表示请求已被成功接收、理解、接受
3xx:重定向--要完成请求必须进行更进一步的操作
4xx:客户端错误--请求有语法错误或请求无法实现
5xx:服务器端错误--服务器未能实现合法的请求
常见状态代码、状态描述、说明:
200 OK//客户端请求成功
400 Bad Request//客户端请求有语法错误,不能被服务器所理解
401 Unauthorized//请求未经授权,这个状态代码必须和WWW-Authenticate报头域一起使用
403 Forbidden//服务器收到请求,但是拒绝提供服务
404 Not Found//请求资源不存在,eg:输入了错误的URL
500 Internal Server Error//服务器发生不可预期的错误
503 Server Unavailable//服务器当前不能处理客户端的请求,一段时间后可能恢复正常
eg:HTTP/1.1 200 OK(CRLF)
2、响应报头后述
3、响应正文就是服务器返回的资源的内容
;
php语言里的一些很简单的代码解释。求解释
第一行,将关键字和指向的页面装入一个数组,可用做url链接,portal指向portal.php
第二行,用点分割指定的系统变量$_SERVER['HTTP_HOST']
第三行,是一个url链接,目标页面为forum.php。在?后面传递“变量=值”对(如:mod=group),
&用来连接这些变量和值对。
第四行,是一组嵌套的三元运算符。类似于if...else判断。
*****
表达式1?表达式2:表达式3
(1)条件表达式的执行顺序:先求解表达式1,若为非0(真)则求解表达式2,此时表达式2的值就作为整个表达式的值。
若表达式1的值为0(假),则求解表达式3,表达式3的值就是整个条件表达式的值。
(2)条件表达式优先于赋值运算符,max=(a>b)?a:b则先求解条件表达式在赋给max。
(3)自右向左运算
a>b? a:c>d? c:d
应该是
a>b? a:(c>d? c:d)
******
最好不要在php中使用多个三元操作符。
使用多个时添加括号:
$a=1>0?1:(2==0?2:(3<0?3:0));
请php 简单 产品分类代码
商品分类展示
设置商品分类显示不仅可使该购物系统的所有商品都分门别类的显示出来,而且为用户选择商品提供了很大的方便。首先应该建立一个单独的type表用来存储商品大类,之后在shangpin表中增加一个typeid字段,该字段中存储的内容是商品大类id值,利用这个值就可以确定该商品属于那一类。商品分类展示是在showfenlei.php中完成的,代码如下:
<!--*******************************showfenlei.php*******************************-->
<?php
include("top.php");
?>
<table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="200" height="438" valign="top" bgcolor="#E8E8E8"><div align="center">
<?php include("left.php");?>
</div></td>
<td width="10" background="images/line2.gif"></td>
<td width="590" valign="top"><table width="590" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left">
<?php
$sql=mysql_query("select* from type order by id desc",$conn);
$info=mysql_fetch_object($sql);
if($info==false)
{
echo"本站暂无商品!";
}
else
{
do
{
echo"<a href='showfenlei.php?id=".$info->id."'>".$info->typename."</a>";
}
while($info=mysql_fetch_object($sql));
}
?>
</div></td>
</tr>
</table>
<?php
if($_GET[id]=="")
{
$sql=mysql_query("select* from type order by id desc limit 0,1",$conn);
$info=mysql_fetch_array($sql);
$id=$info[id];
}
else
{
$id=$_GET[id];
}
$sql1=mysql_query("select* from type where id=".$id."",$conn);
$info1=mysql_fetch_array($sql1);
$sql=mysql_query("select count(*) as total from shangpin where typeid='".$id."' order by addtime desc",$conn);
$info=mysql_fetch_array($sql);
$total=$info[total];
if($total==0)
{
echo"<div align='center'>本站暂无该类产品!</div>";
}
else
{
?>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="left"><span style="color:#666666; font-weight: bold"><span style="color:#000000">本类商品>></span><?php echo$info1[typename];?></span>
</div></td>
</tr>
</table>
<table width="550" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="images/line1.gif"></td>
</tr>
</table>
<table width="550" height="70" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
$pagesize=10;
if($total<=$pagesize)
{
$pagecount=1;
}
if(($total%$pagesize)!=0)
{
$pagecount=intval($total/$pagesize)+1;
}
else
{
$pagecount=$total/$pagesize;
}
if(($_GET[page])=="")
{
$page=1;
}
else
{
$page=intval($_GET[page]);
}
$sql1=mysql_query("select* from shangpin where typeid=".$id." order by addtime desc limit".($page-1)*$pagesize.",$pagesize",$conn);
while($info1=mysql_fetch_array($sql1))//显示商品信息
{
?>
……
<?php
}
?>
</table>
<table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="right">本站共有该类商品
<?php
echo$total;
?>
件每页显示<?php echo$pagesize;?>件第<?php echo$page;?>页/共<?php echo$pagecount;?>页
<?php
if($page>=2)//商品分页显示
{
?>
<a rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=1" title="首页"><font face="webdings"> 9</font></a>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$page-1;?>" title="前一页"><font face="webdings"> 7</font></a>
<?php
}
if($pagecount<=4){
for($i=1;$i<=$pagecount;$i++){
?>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$i;?>"><?php echo$i;?></a>
<?php
}
}
else
{
for($i=1;$i<=4;$i++){
?>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$i;?>"><?php echo$i;?></a>
<?php
}
?>
<a rel="external nofollow" rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$page-1;?>" title="后一页"><font face="webdings"> 8</font></a>
<a rel="external nofollow" href="showfenlei.php?id=<?php echo$id;?>&page=<?php echo$pagecount;?>" title="尾页"><font face="webdings">:</font></a>
<?php
}
?>
</div></td>
</tr>
</table>
<?php
}
?>
</td>
</tr>
</table>
<?php
include("bottom.php");
?>
END,本文到此结束,如果可以帮助到大家,还望关注本站哦!