For orignial post kindly visit www.apepoint.com
for the original contents kindly visit www.apepoint.com
Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site A visitor accessing your web site is assigned a unique id, the so-called session id.
A normal HTML website will not pass data from one page to another. In other words, all information is forgotten when a new page is loaded. A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, e-mail id , etc). However, this session information is temporary and is usually deleted very quickly after the user has left the website that uses sessions
Sessions work by creating a unique identification(UID) number for each visitor and storing variables based on this ID. This helps to prevent two users' data from getting confused with one another when visiting the same webpage
starting a php session
Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent.
PHP Code:
session_start();
?>
Creating and reading session variables
Variables can be assigned to a session by using the $_SESSION global variable. Any value that is assigned to a $_SESSION variableis readable by any script that is served by your web server and is viewed in the same session.
session_start();
$_SESSION['views'] = 1; // store session data
echo "Pageviews = ". $_SESSION['views']; //retrieve data
?>
Cleaning and destroying your session.
some time we want to clear a session data so we can use the below function
unset($_SESSION['userid']);
You can also completely destroy the session entirely by calling the session_destroy function.
PHP Code:
session_start();
session_destroy();
?>
HTTP Headers
There are several things importance of HTTP header but generally in php we use in re-direct and in graphics below is an example of a redirect code
header("Location:home.php");
the script will redirect to home.php page
Cookies
PHP transparently supports HTTP cookies. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users. You can set cookies using the setcookie() or setrawcookie() function. Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the browser setcookie — Send a cookie
php start
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
php close
php start
// Print an individual cookie
echo $_COOKIE["TestCookie"];
echo $HTTP_COOKIE_VARS["TestCookie"];
// Another way to debug/test is to view all cookies
print_r($_COOKIE);
php close
Any cookies sent to you from the client will automatically be included into a $_COOKIE auto-global array if variables_order contains "C". If you wish to assign multiple values to a single cookie, just add [] to the cookie name.
Popular Posts
-
Form processing in PHP kindly visit www.apepoint.com for the original content of this blog Before moving to this chapter i must sug...
-
PHP basis programming kindly visit www.apepoint.com for the original content of this blog. Here in this chapter we will learn how t...
-
For orignial post kindly visit www.apepoint.com File manager A file manager or file browser is a computer program that provides a user inter...
-
For orignial post kindly visit www.apepoint.com When we work with MySQL we need to execute a number of query .We can execute almost all t...
-
On window Here the process is straight forward just download WAMP server and double click it will automatically install and you can run you ...
-
Object Oriented Programming PHP For orignial post kindly visit www.apepoint.com Object oriented programming is the dominant programming para...
-
PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce...
-
For orignial post kindly visit www.apepoint.com for the original contents kindly visit www.apepoint.com Session support in PHP consists of a...
-
PHP array In c like language we all studied that an array is a collection of similar elements. These similar elements could be all int or ...
-
For orignial post kindly visit www.apepoint.com In a number of website you might have seen that the gadget which says that your IP Addres...
No comments:
Post a Comment