General |  Social Media |  Miscellaneous
Login | Register
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Who can be called a true monk ? ☛ God arranges everything ☛ Faith in god ☛ What is a Rotary Encoder? How does it work? ☛ Things to Know About PLC and SCADA ☛ According to Ramayana, why do women wear jewelry? ☛ After registering an FIR, can I not apply for a government job ☛ Daughter: A angel of his father ☛ How VOIP Phone System is Useful For your Business? ☛ test 
Home > Innovation & Technology > PHP

Session in PHP


Session in PHP

If you want to pass important information from one page to another pages or if you want to store important information like user id, password then PHP session is best option for you.

PHP session is a global variable that is stored on the server. A variable that could be used on various page, that is called session in PHP. Cookies are also worked similar to session but cookies are stored on the user computer and PHP session is not stored on user computers. Each PHP session variables have a unique ID which is used to getting session information from the server. Comparisons of cookies, Session variables have large capacity for storing information.

When you work on application, you need to use one information on various pages then PHP session variables solve this issue by storing information in session. Session variable will start when you open application and it will close automatically when you close browser by default. Otherwise you can destroy session variable by some PHP function.

Also if you need a permanent storage of variable, then you have to store the information in your database.

A session creates a temporary directory on server for storing session variable where session variable and their values are stored. A same user can use this variable during surfing on applications. The server will terminate session after 30 minutes when users are not active on application.

How to start a PHP Session?

In order to create a session in PHP, you have to call the session_start() function. All session variables are stored in the PHP global variable $_SESSION.

Note: session_start() function will be write before start a any HTML tags.

For Example:

 

 

 

 

 

 

 

 

 

 

How to retrieve PHP session value?

Remember that all session variable values are stored into global variable like $_SESSION. Here you have to mind, don’t use session_start() function after HTML tags. session_start() function will be shows before starting all HTML tags.

For example:

 

 

 

 

 

”;

echo "City name  is " . $_SESSION["city "] ;

?>

 

 

 

 

How to modify session in PHP?

 

For modifying or changing session variables, just overwrite session variable.

 

For Example:

 

 

 

 

 

”;

echo "City name  is " . $_SESSION["city "] ;

?>

 

 

 

 

 

How to destroy session in PHP or How to delete session in PHP?

 

For destroying session variables, we have three options.

  1. unset()
  2. session_unset()
  3. session_destroy()

 

What is the difference between session_unset() and session_destroy() ?

 

If you want to delete single variable, then you have to use unset() function. unset() is destroy single variable in application.

If you want to remove all session variable, then you have to use session_unset(). session_unset() function is remove all session variable.

If you want to delete all session then you have to use session_destroy() function. session_destroy() is destroy all session from whole application.

 

For example:

 

 

 

 

 

 

 

 

 

For more details about session, visit: PHP Session

Written By: Charles Miller Published in PHP


Search

Publish your passions on srcraftblog.com

Latest Post

☛ Who can be called a true monk ?

☛ God arranges everything

☛ Faith in god

☛ What is a Rotary Encoder? How does it work?

☛ Things to Know About PLC and SCADA

☛ According to Ramayana, why do women wear jewelry?

☛ After registering an FIR, can I not apply for a government job

☛ Daughter: A angel of his father

☛ 'Gurukul' literally means 'family of Guru' or 'clan of Guru'

☛ When does mother's honor get less


We are accepting well-written informative Guest Posts on srcraftblog.com

Innovation & Technology

Artificial Intelligent blogs
Cryptocurrency blogs
Digital India blogs
Data science blogs
Neuroscience blogs
Programming blogs

Physical science

Physics blogs
Chemistry blogs
Earth science blogs
Geology blogs
Oceanography blogs
Meteorology blogs

Industry

Business blogs
Economy blogs
Freelancing blogs
Leadership blogs
Productivity blogs
Work blogs

Society

Basic income blogs
Education blogs
Environment blogs
Media blogs
Philosophy blogs
Women blogs
About us |  Write for us |  Terms and conditions |  Contact us

© 2021 SRCRAFT INIDA