Blogger news

What is Session in PHP[$_SESSION],Session Variables,PHP Session Functions,using session in php

taabin | 03:14 | 0 comments

What is Session in PHP, Session Variables, PHP Session Functions,session in php Using

PHP Session Variables :

           When you square measure operating with associate degree application, you open it, do some changes and so you close up it. this can be very like a Session. the pc is aware of World Health Organization you're. It is aware of once you begin the appliance and once you finish. however on the web there's one problem: the online server doesn't understand World Health Organization you're and what you are doing as a result of the protocol address does not maintain state.

             A PHP session solves this downside by permitting you to store user data on the server for later use (i.e. username, searching things, etc). However, session data is temporary and can be deleted when the user has left the web site. If you would like a permanent storage you'll need to store the info during a info.

Sessions work by making a singular id (UID) for every traveller and store variables supported this UID. The UID is either keep during a cookie or is propagated within the address.

Starting a PHP Session : 

     Before you'll be able to store user data in your PHP session, you need to initial commence the session.

(or)

         An associative array containing session variables on the market to the present script. See the Session functions documentation for additional data on however this can be used.

$HTTP_SESSION_VARS contains identical initial data, however isn't a superglobal. 
(Note : that $HTTP_SESSION_VARS and $_SESSION square measure completely different variables which PHP handles them as such)

(or)

           Session support in PHP consists of some way to preserve bound information across resulting accesses. this allows you to make additional custom-made  applications and increase the attractiveness of your electronic computer. All data is within the Session reference section.

Note: The session_start() operate should seem BEFORE the  tag.



         The code higher than can register the user's session with the server, permit you to start out saving user data, and assign a UID for that user's session.

Storing a Session Variable :
The correct thanks to store and retrieve session variables is to use the PHP $_SESSION variable:


session_start();
// store session information
$_SESSION['views']=1;
?>

//retrieve session information
echo "Pageviews=". $_SESSION['views'];
?>



Output:

Pageviews=1

        In the example below, we have a tendency to produce a straightforward page-views counter. The isset() operate checks if the "views" variable has already been set. If "views" has been set, we will increment our counter. If "views" does not exist, we have a tendency to produce a "views" variable, and set it to 1:


session_start();

if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
echo "Views=". $_SESSION['views'];
?>

Destroying a Session :
    If you want to delete some session information, you'll be able to use the unset() or the session_destroy() operate.

The unset() operate is employed to free the desired session variable:


session_start();
if(isset($_SESSION['views']))
  unset($_SESSION['views']);
?>

You can conjointly utterly destroy the session by business the session_destroy() function:


session_destroy();
?>


Note: session_destroy() can reset your session and you may lose all of your keep session information.

using session in php

Category:

About GalleryBloggerTemplates.com:
GalleryBloggerTemplates.com is Free Blogger Templates Gallery. We provide Blogger templates for free. You can find about tutorials, blogger hacks, SEO optimization, tips and tricks here!

0 comments