三、session应用举例
以下这些例子片断仅供参考,你可以定制也可以不定制session,随你便
(1)用于用户认证
session_start();
$dbh=MySQL_connect("localhost:3306","xxxx","xxxx");
MySQL_select_db("znsoft");//选择数据库
$query="selectuseridfromreguserwhereuserid='$userid'andpass='$pass'";
//$userid$pass是登录form传递过来的用户名和密码
$res=MySQL_query($query,$dbh);
if($row=MySQL_fetch($res))
{
$reguser=$row[0];
?>
<script> <br />
alert("ok,哥们,欢迎你!"); <br />
</script>
}
else
{
$reguser="";
?>
<script> <br />
alert("sorry,你不是注册用户!"); <br />
</script>
//你自己放上代码吧
}
session_register("reguser");
?>
另一页面中检查是否已经登录
================
session_start();
if(isset($reguser)&&$reguser!="")//已经登录
{
echo"欢迎你,哥们";
}
else//没有登录呀
echo"请注册吧";
?>
退出功能
===============================
session_destroy();
//或$reguser="";
?>
(2)用于传递变量
本程序用于在页面之间传递变量
$name="m.y";
if(!sesion_is_registered("name"))//没有注册session变量name
session_register("name");//注册变量name
?>
第二页
===================
echo$name;
//不想用了,删掉吧
if(session_is_registered("name"))//是否注册,如果已经注册
session_unregister("name");//当然删掉啦
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.