Home Backend Development PHP Tutorial Full session tutorial (3)_PHP tutorial

Full session tutorial (3)_PHP tutorial

Jul 13, 2016 pm 05:11 PM
session three example Can custom made application Tutorial

3. Session application examples

The following example snippets are for reference only. You can customize the session or not, as you like
(1) Used for user authentication
<?
session_start();
$dbh=MySQL_connect("localhost:3306","xxxx","xxxx");
MySQL_select_db("znsoft");//Select database
$query="selectuseridfromreguserwhereuserid='$userid'andpass='$pass'";
//$userid$pass is the username and password passed by the login form
$res=MySQL_query($query,$dbh);
if($row=MySQL_fetch($res))
{
$reguser=$row[0];
?>
<script>
alert("ok, buddy, welcome!");
</script>
<?
}
else
{
$reguser="";
?>
<script>
alert("sorry, you are not a registered user!");
</script>
<?

//Put the code yourself
}
session_register("reguser");
?>
Check whether you are logged in on another page
================
<?
session_start();

if(isset($reguser)&&$reguser!="")//Already logged in
{
echo "Welcome, buddy";
}
else//Not logged in
echo "Please register";
?>
Exit function
===============================
<?
session_destroy();
//or $reguser="";
?>

(2) is used to pass variables

This program is used to transfer variables between pages
<?
$name="m.y";
if(!session_is_registered("name"))//The session variable name is not registered
session_register("name");//Register variable name
?>
Second page
===================
<?
echo$name;

//If you don’t want to use it anymore, delete it
if(session_is_registered("name"))//Whether to register, if already registered
session_unregister("name");//Delete it of course
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629566.htmlTechArticle3. Session application examples The following examples are for reference only. You can customize the session or not, it’s up to you. Is (1) used for user authentication? session_start(); $dbh=MySQL_connect(localh...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on how to use Dewu Tutorial on how to use Dewu Mar 21, 2024 pm 01:40 PM

Tutorial on how to use Dewu

The role and practical application of arrow symbols in PHP The role and practical application of arrow symbols in PHP Mar 22, 2024 am 11:30 AM

The role and practical application of arrow symbols in PHP

How to Undo Delete from Home Screen in iPhone How to Undo Delete from Home Screen in iPhone Apr 17, 2024 pm 07:37 PM

How to Undo Delete from Home Screen in iPhone

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

Tutorial on how to turn off the payment sound on WeChat

Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones Mar 22, 2024 pm 12:21 PM

Experts teach you! The Correct Way to Cut Long Pictures on Huawei Mobile Phones

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

In summer, you must try shooting a rainbow

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to convert int type to string

Honor mobile phone Hongmeng system upgrade tutorial Honor mobile phone Hongmeng system upgrade tutorial Mar 23, 2024 pm 12:45 PM

Honor mobile phone Hongmeng system upgrade tutorial

See all articles