|
|
|
The below code is a very simple example of Session.
Please note that the "session_start" statement *must* be the first line of your code.
To see the example at work, please review:
http://www.xn--ovg.com/session
tedd
--- copy below and save as session1.php -----
|
<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Stuff by tedd</title>
</head>
<body>
<h1>tedd's session stuff (page 1)</h1>
<hr>
<h3>PHPSESSID = <?php echo session_id(); ?></h3>
<hr>
<h2>Click the next page and see numbr of visits during this visit.</h2>
<a href="session2.php?<?php echo( SID ); ?>">Next page</a>
</body>
</html> | |
--- copy below and save as session2.php -----
| <?php
session_start();
($_SESSION['count']) ? $_SESSION['count']++ : $_SESSION['count'] = 1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Stuff by tedd</title>
</head>
<body>
<h1>tedd's session stuff (page 2)</h1>
<hr>
<h3>PHPSESSID = <?php echo session_id(); ?></h3>
<hr>
<h2>You have been here <?php echo( $_SESSION['count'] ); ?> times in this session.</h2>
<a href="session1.php?<?php echo( SID ); ?>">Previous page</a>
</body>
</html>
</html> | | |
|
| Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | session out Timer Categories : PHP, Sessions, Security, Beginner Guides | | | Using PHP im HTML image tags Categories : PHP, HTML and PHP, Graphics, Beginner Guides | | | Securing Web Forms with Simple PHP-CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart)
Categories : PHP, Security, GD image library, Sessions | | | Newbie Notes #7 - Ridiculous regex Categories : PHP, Beginner Guides, Regexps | | | CSS style switcher Categories : PHP, CSS, HTML and PHP, Arrays, Sessions | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0 Categories : PHP, Sessions, Databases, MySQL | | | GuestBook Light - a plug and play application for any website. Categories : PHP, Complete Programs, Filesystem, Sessions | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance. Categories : HTML, PHP, HTML and PHP, Beginner Guides | | | Form Validation Using PHP to highlight non valid fields Categories : PHP, Form Processing, Data Validation, Beginner Guides | | | Security, Password lock out after three tries, authorization fails and is logged locked out of account till admin decides he will unlock it. Categories : Sessions, PHP, MySQL, PHP Options and Info | | | PHP and javascript mouseover, mouseout, and mousedown events Categories : PHP, Java Script, Form Processing, Beginner Guides | |
| | | | Dorival Martinez wrote :1829
Congratulations. I am a begginer in PHP and your explanation about sessions was the best that I ever read.
Sincerely,
Dorival, from Brazil.
| |
|
|