answersLogoWhite

0

All you have to do to maintain a session is start it before you call any variables. Once you've started the session, you can store variables for use in later scripts.

Beware though, once the user closes the browser, the sessions' over.

I'd use the following

SCRIPT 1:

<?php

// Start session

session_start();

// Set some variables (this simulates form input)

$_SESSION['answers']['Q1'] = 18;

$_SESSION['answers']['Q2'] = 36;

$_SESSION['answers']['Q4'] = "Fred";

?>

=============================

Hope that helps...

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Basic Math

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: &lt;?php // allow sessions to work on script session_start(); // set up a session called my number $_SESSION['my_number'] = 1; ?&gt; 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: &lt;?php unset($_SESSION['my_number']); ?&gt; To destroy all sessions in one go you can call the session_destroy() function. This will save you some time. &lt;?php session_destroy(); ?&gt;


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.


What is a php session?

A PHP session is a concept where specific variables (and their respective values) are carried throughout a user's viewing of a PHP-driven website. These sessions can be initialized and continued using the session_start() function. The session values are stored in the $_SESSION global variable. For more information, see the php.net documentation of session functions.


What is a parse error in php?

Parse error in PHP means that your script is invalid - it is not compliant with the programming language specification. After parse error script is no longer executed.


How do you delay a PHP script?

To delay a script in seconds you would use the sleep() function as shown below: &lt;?php echo "hello"; sleep(5); // delays the script for 5 seconds echo "finished"; ?&gt;

Related Questions

How can you run a PHP script?

A php script can only be executed within a Web server that runs php.


How do you create a web mail script using PHP?

You can use phpMailer() Or, you can use mail() PHP function to send emails via PHP script.


How do I get rid of PHP in Charter's home page?

Open the PHP script and delete the PHP from it.


How do you create a PHP script?

To create a PHP script all you have to do is create a new file, then save the file as "filename.php". It must have a .php file extension.After that open the file and put in the PHP tags like shown.Then you write your PHP script within those tags and upload to your web space and check it out.


How can you execute a PHP script using command line?

2 Methods: 1. You execute your php binary (in linux, make sure you have php-cli installed) and pass the script as an argument. EG ($: /usr/bin/php /home/user/script.php) 2. A sh'bang in the first line of your script, with the full path of your php executable: #!/usr/bin/php -q &lt;?php ScriptStuff(); ?&gt;


Can you provide free web hosting on a site from a PHP script?

If you created a PHP script that could provide that for people then yes you could.


How do you use PHP in HTML?

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


What are semantics in PHP?

PHP is related with HTML. HTML can be included into PHP script as well as PHP script can be included into HTML code. PHP begins and ends with &lt;?php ?&gt;. PHP is mix of few languages so semantics is mixed too.


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: &lt;?php // allow sessions to work on script session_start(); // set up a session called my number $_SESSION['my_number'] = 1; ?&gt; 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: &lt;?php unset($_SESSION['my_number']); ?&gt; To destroy all sessions in one go you can call the session_destroy() function. This will save you some time. &lt;?php session_destroy(); ?&gt;


Write down a PHP code to add a session variable?

The preferred way is to simply alter the session superglobal. &lt;?php $_SESSION['variable'] = "value"; ?&gt;


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.


What is a php session?

A PHP session is a concept where specific variables (and their respective values) are carried throughout a user's viewing of a PHP-driven website. These sessions can be initialized and continued using the session_start() function. The session values are stored in the $_SESSION global variable. For more information, see the php.net documentation of session functions.