会话购物车

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
//session_start();//开启session

//HTTP,无状态性
//SESSION COOKIE

//SESSION:存储在服务端的,每个人存一份,可以存储任意类型的数据,默认过期时间15分钟
//COOKIE:存储在客户端的,每个人存一份,只能存储字符串,默认永不过期

//$_SESSION["uid"] = "zhangsan";//写入SESSION

//echo $_SESSION["uid"];

//setcookie("uid","zhangsan"); //设置COOKIE

?>
<a href="test1.php">跳转</a>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
//session_start();
//echo $_COOKIE["uid"];
//echo $_SESSION["uid"];
?>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>水果名称</td>
<td>水果价格</td>
<td>水果产地</td>
<td>水果库存</td>
<td>操作</td>
</tr>
<?php

include("../DBDA.php");
$db = new DBDA();

$sql = "select * from fruit";

$attr = $db->Query($sql);

foreach($attr as $v)
{
echo "<tr><td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td><a href='addgwc.php?code={$v[0]}'>加入购物车</a></td></tr>";
}

?>
</table>

<a href="gouwuche.php">查看购物车</a>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
session_start();

if(empty($_SESSION["uid"]))
{
header("location:login.php");
}

echo $_SESSION["uid"];
?>
</body>
</html>

<?php
session_start();
include("../DBDA.php");
$db = new DBDA();

$uid = $_POST["uid"];
$pwd = $_POST["pwd"];

$sql = "select count(*) from Users where Uid='{$uid}' and Pwd = '{$pwd}'";

$r = $db->StrQuery($sql);

if($r==1)
{
$_SESSION["uid"] = $uid;
header("location:main.php");
}
else
{
header("location:login.php");
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>登录</h1>
<form action="loginchuli.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="text" name="pwd" /></div>
<div><input type="submit" value="登录" /></div>
</form>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>水果名称</td>
<td>水果价格</td>
<td>数量</td>
</tr>
<?php
session_start();

include("../DBDA.php");
$db = new DBDA();

$attr = $_SESSION["sg"];

foreach($attr as $v)
{
$sql = "select Name,Price from fruit where Ids='{$v[0]}'";

$arr = $db->Query($sql);

echo "<tr><td>{$arr[0][0]}</td>
<td>{$arr[0][1]}</td>
<td>{$v[1]}</td></tr>";
}

?>
</table>
</body>
</html>

<?php
session_start();

$code = $_GET["code"];

//如果第一次点击
if(empty($_SESSION["sg"]))
{
$attr = array(array($code,1));
$_SESSION["sg"] = $attr;
}
else
{
//第n次点击,n!=1
$attr = $_SESSION["sg"];

//判断该水果师是否已经存在
if(iscunzai($code))
{
foreach($attr as $k=>$v)
{
if($v[0]==$code)
{
$attr[$k][1] = $v[1]+1;
}
}

$_SESSION["sg"] = $attr;
}
else
{
$arr = array($code,1);
array_push($attr,$arr);

$_SESSION["sg"] = $attr;
}

}

function iscunzai($c)
{
$attr = $_SESSION["sg"];

$b = false;

foreach($attr as $v)
{
$b = $b || in_array($c,$v);
}

return $b;
}

header("location:showlist.php");

php第二十六节课的更多相关文章

  1. 风炫安全WEB安全学习第二十六节课 XSS常见绕过防御技巧

    风炫安全WEB安全学习第二十六节课 XSS常见绕过防御技巧 XSS绕过-过滤-编码 核心思想 后台过滤了特殊字符,比如说

  2. centos linux系统日常管理3 服务管理ntsysv,chkconfig,系统日志rsyslog,last ,lastb ,exec,xargs,dmesg,screen,nohup,curl,ping ,telnet,traceroute ,dig ,nc,nmap,host,nethogs 第十六节课

    centos linux系统日常管理3  服务管理ntsysv,chkconfig,系统日志rsyslog,last ,lastb ,exec,xargs,dmesg,screen,nohup,cur ...

  3. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  4. centos MySQL主从配置 ntsysv chkconfig setup命令 配置MySQL 主从 子shell MySQL备份 kill命令 pid文件 discuz!论坛数据库读写分离 双主搭建 mysql.history 第二十九节课

    centos  MySQL主从配置 ntsysv   chkconfig  setup命令  配置MySQL 主从 子shell  MySQL备份  kill命令  pid文件  discuz!论坛数 ...

  5. centos lamp/lnmp阶段复习 以后搬迁discuz论坛不需要重新安装,只需修改配置文件即可 安装wordpress 安装phpmyadmin 定时备份mysql两种方法 第二十五节课

    centos  lamp/lnmp阶段复习 以后搬迁discuz论坛不需要重新安装,只需修改配置文件即可 安装wordpress  安装phpmyadmin  定时备份mysql两种方法  第二十五节 ...

  6. 大白话5分钟带你走进人工智能-第二十六节决策树系列之Cart回归树及其参数(5)

                                                    第二十六节决策树系列之Cart回归树及其参数(5) 上一节我们讲了不同的决策树对应的计算纯度的计算方法, ...

  7. 风炫安全web安全学习第三十六节课-15种上传漏洞讲解(一)

    风炫安全web安全学习第三十六节课 15种上传漏洞讲解(一) 文件上传漏洞 0x01 漏洞描述和原理 文件上传漏洞可以说是日常渗透测试用得最多的一个漏洞,因为用它获得服务器权限最快最直接.但是想真正把 ...

  8. 风炫安全web安全学习第二十九节课 CSRF防御措施

    风炫安全web安全学习第二十九节课 CSRF防御措施 CSRF防御措施 增加token验证 对关键操作增加token验证,token值必须随机,每次都不一样 关于安全的会话管理(SESSION) 不要 ...

  9. 风炫安全WEB安全学习第二十五节课 利用XSS键盘记录

    风炫安全WEB安全学习第二十五节课 利用XSS键盘记录 XSS键盘记录 同源策略是浏览器的一个安全功能,不同源的客户端脚本在没有明确授权的情况下,不能读写对方资源.所以xyz.com下的js脚本采用a ...

随机推荐

  1. Codeforces Round #322 (Div. 2) D. Three Logos 模拟

                                                      D. Three Logos Three companies decided to order a ...

  2. the “identity” of an object

    2. Built-in Functions — Python 3.6.5 documentation https://docs.python.org/3.6/library/functions.htm ...

  3. go10---struct

    package main import ( "fmt" ) type test struct{} //空的结构体 type person struct { name string ...

  4. Tool:Adobe Photoshop

    ylbtech-Tool-Adobe:Adobe Photoshop 1.返回顶部 1. Adobe Photoshop,简称“PS”,是由Adobe Systems开发和发行的图像处理软件. Pho ...

  5. 【161】BASH相关文章链接

    ---恢复内容开始--- 1. Linux cat命令详解  --<cat>-- 新建文件 file1.txt,随便输入几行文字 cat 'file1.txt' #显示 'file1.tx ...

  6. 关于file文件操作的头文件 【LINUX】 (转载)

    转自:http://blog.csdn.net/figo77ll/article/details/3156052 Linux下如果要对文件进行读取访问,需要包含至少以下两个头文件: #inlcude ...

  7. bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛【二分+贪心】

    二分答案,贪心判定 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...

  8. 仓鼠找sugar II

    题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a,是任意的)他的基友卧室(b,还是任意的).(注 ...

  9. [CREC2007/CQOI2014]robotic sort

    Description 一个实验室里有n个长短不一的试管.你的任务是编写一段程序,用机器臂把它们按照高度从小到大的顺序排列. 对于高度相同的试管,排序前后的相对位置应保持不变.排序方法如图所示. 排序 ...

  10. win10下spark+Python开发环境配置

    Step0:安装好Java ,jdk Step1:下载好: Step2: 将解压后的hadoop和spark设置好环境变量: 在系统path变量里面+: Step3: 使用pip安装 py4j : p ...