Ad block is installed and active. Please support us by disabling it.
HomeThursday, September 21, 2017, 03:19:13
1

PHP Cookies and Sessions Tutorial

Monday, February 9, 15, 13:35:14, 3 Yaers Ago Via wain, Hits: 2907
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.

Getimagesize

Getimagesize function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondant HTTP content type.

Creating a CAPTCHA with PHP :: PHP Tutorial

Captcha Image, This tutorial will show you how to create a form with Captcha.

Adsense crawler errors and robots.txt

How to fix Google AdSense crawler errors in robots.txt

php Array

These functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.

How to check checkbox checked

Checking if checkbox is checked with jQuery

Comments 1.1. :: PHP Script

This script allows your visitors to add comments to any single page on your web site.

Stack Overflow Clone Script - Ja2BU

Open source question and answer script written in PHP, MySQL and jQuery. Main features are: SEO friendly url's, private message system, rating system, comments system.

Contact Us PHP Form 1.1.

A contact us form with email and form field validation. It allows your visitors to send you an email directly from your website.

Captcha V2 - Free PHP Script

PHP Captcha protection image Version 2, - Requirement(s): PHP Server, GD Library
About Author

wain

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