answersLogoWhite

0

Why do you use sessions in PHP?

User Avatar

Anonymous

11y ago
Updated: 8/16/2019

There are a lot of reasons to use session. Mostly to keep sensitive data housed on the server (and not on user's computer in cookies).

It is also a much easier and more dynamic way to store data than Cookies, and far more reliable than constant GET or POST passing.

As http is a stateless transaction, there's no way to tell what the user i.e. in a shop wants to buy, or has already stored. In come PHP sessions, which are carrying an ID and are stored similar to cookies in your browser. Usually a session is lost as soon as the browser closes or the user logs off. It furthermore helps to keep information private between the user and the server machine.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

How do you use sessions in PHP?

Sessions in PHP are easy to learn and set up, first of all you need to make sure you use the function session_start() at the start of each script to make sure the sessions work. Then all you need to do is the following to store information in sessions: <?php // allow sessions to work on script session_start(); // set up a session called my number $_SESSION['my_number'] = 1; ?> That's all you need to do to set up and store data in a session. Now if you want to delete a session you will need to use the unset() function like shown below: <?php unset($_SESSION['my_number']); ?> To destroy all sessions in one go you can call the session_destroy() function. This will save you some time. <?php session_destroy(); ?>


What is the purpose of a PHP session?

A PHP session serves quite a few purposes. PHP sessions store data that the web application developer would like to have preserved across the different page loads.


How can you create a language converter for website in English to Spanish in PHP?

You can use PHP to create a language converter for a website by storing language translations in a database or files, and then using PHP to dynamically switch the content based on the selected language. You can create language files for each language, and then use PHP sessions or cookies to store the user's language preference across pages. Finally, use PHP functions to display the content in the appropriate language based on the user's selection.


How do you update and delete data from PHP sessions?

To update/delete data from a session all you need to do is the following: <?php // to update the session, you just overwrite it like a normal variable $_SESSION['name'] = "pizza"; // to delete a sessions data you can do this $_SESSION['name'] = ""; ?>


What is the use of a question mark in php?

It is used to tell the sever to use the PHP parser. To begin php you must use <?php, and to end it, it is ?>.


How do you use PHP in HTML?

You can't use PHP in an HTML document, but you can use HTML in PHP script.


How do you declare session in javascript?

You can't. Sessions are a server-side technology. To properly implement a session, you have to use a server-side language like PHP, ASP, or Ruby.


How do you create a webmail application with PHP?

Creating a webmail application in PHP involves using the related POP3 or IMAP libraries to connect to the mail system and cookies/sessions to save authentication information.


Why should you use PHP and not JSP?

Firstly, this is wrong question. The right one would be WHEN should you use PHP, not JSP? or, WHEN should you use PHP and WHEN JSP?


How do you enable PHP sessions?

Find your php.ini file (which holds all the settings for PHP, and how it should work).Under the "sessions" section, find the directive "session.save_hander." Unless you're directed otherwise, and you want sessions enabled, this directive should be set to the string "files."If session problems arise, find the directive "session.save_path," and make sure the current path it's set to actually exists (and that PHP can write to it). PHP does not create this directory; you need to.Still not working? Go to the directory path that session files are saved in (as noted in the "session.save_path" directive) and see if there are session files being created when you start a session in a PHP script. If they are, then your scripts are most likely the problem. If the newly created sessions are empty, make sure that you are actually putting data in them, and that you're not resetting the $_SESSION global variable anywhere.If they aren't, then it may help to reinstall PHP, or get further assistance elsewhere.


Where could one find information about how to use PHP 5?

You can find information about how to use PHP 5 on the official PHP website, PHP.net, through the PHP 5 documentation section. Additionally, online tutorials, forums, and books dedicated to PHP programming are great resources to learn how to use PHP 5 effectively.


How do you use XML in PHP?

PHP 5 has a XML parser called SimpleXML that you could use.