HomeMonday, June 18, 2018, 15:09:17
1

PHP Cookies and Sessions Tutorial

Monday, February 9, 15, 13:35:14, 3 Yaers Ago Via wain, Hits: 6517
PHP Cookies and Sessions Tutorials
index.php

Code:
<?php @session_start();
if(isset($_POST['Submit']))
{
setcookie("cookieuser", $_POST['username'], time()+3600);
setcookie("cookiepass", $_POST['password'], time()+3600);
print_r ($_COOKIE);
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
print_r ($_SESSION);
echo"<a href=\"members.php\">members</a>";
}else{
if(isset($_SESSION['username']) &&
isset($_SESSION['password'])){
echo $_SESSION['username'] . "-" . $_SESSION['password'] ;
}else{
echo"<strong style=\"color:red\">no session</strong>";
echo" <a href=\"members.php\">members</a>";
}
?>
<form method="post" action="index.php">
<input type="text" name="username" ><br>
<input type="text" name="password" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>


members.php

Code:
<?php @session_start();
if(isset($_COOKIE['cookieuser']) &&
isset($_COOKIE['cookiepass'])){
$_SESSION['username'] = $_COOKIE['cookieuser'];
$_SESSION['password'] = $_COOKIE['cookiepass'];
echo"cool " . $_SESSION['username'];
echo" <a href=\"destroysession.php\">destroysession</a>";
}else{
echo"no session ";
echo"<a href=\"index.php\">login</a>";
die();
}
?>
<h1>members area</h1>


destroysession.php

Code:
<?php @session_start();
print_r ($_COOKIE);
setcookie("cookieuser", "", time()-3600);
setcookie("cookiepass", "", time()-3600);

if(isset($_SESSION['username']) &&
isset($_SESSION['password'])){
unset($_SESSION['username']);
unset($_SESSION['password']);
}else{
echo"<strong>no session</strong> ";
}
$_SESSION = array();
session_destroy();
echo"<a href=\"index.php\"> index.php</a>";
?>

Sign In

Sponsor
Related

Block Visitors From Specific IP Address

Learn How To Restrict Users From Different IP Addresses.

Syntax highlighting in Smarty

Syntax highlighting for Smarty - Google Code Prettify

Contact Us 2.0. with HTML Page and Pop Up Frame

This is the same Contact Us 2.0. that is in this forum, But I have added more options to this script and a html page with a very nice pop Up frame that DONT get block by any pop Up software. Many websites use this type of script to bypass the blocking…

PHP Form Basic

PHP Form - PHP form basic, Requirement(s): PHP Server

E-Cards 1.1. PHP Script

This script will allow your visitors to send e-cards to their friends. It features admin notification and HTML output.To use the "e-cards" script completely free , the "powered by" link at the bottom of the pages must stay intact.

MySQL Inner Join

MySQL Inner Join - Creating Dynamic Webpages Using PHP and MySQL, Requirement(s): PHP Server, MySQL

PHP Redirect

Header (location) redirect must be processed before any output to the browser.

PHP/MySQL Bookmarklet - PHP Tutorial

PHP/MySQL bookmarklet, bookmark current page, PHP/MySQL tutorial.

Math Captcha V6

PHP Math Captcha Image Version 6

PHP Form Validation

PHP form validation :: PHP tutorial, requirement(s): PHP Server
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Sun, Mar 18, 18
So far has created 115 entries.
wain
This author has not yet filled in any details.