Getting PHP 5.2.x To Run on Mac Tiger 10.5

So, you decided to upgrade to Mac Tiger Workstation and your PHP service stopped working. No fear, as PHP will still work fine once you make a simple change to your Apache 2 configuration file. Previous versions of Mac OS 10.4 and below were using Ap...

PHP Session Management Tutorial (Part 2) - Storing and Retrieving Data Print E-mail
User Rating: / 8
PoorBest 
In first part of this tutorial series we learned how to use PHP session_start() and session_register() function.
Now, we are going to learn how to store data using session variables and then how to retrieve it on next page.
We will show you this using the full script code which you can test at your end easily. --------------------------------
FILE 1 - phpsessionstore.php
--------------------------------


Code :

<HTML>
    <HEAD>
        <TITLE>
            Storing data in sessions
        </TITLE>
    </HEAD>

    <BODY>
        <CENTER>
            <H1>
                Storing data in sessions
            </H1>

            <?php
                session_start();
                $_SESSION['dollar'] = "50";
            ?>

            Stored the value of dollar as 50.
            <BR>
            To retrieve the dollar value in a new page, <a href="phpsessionret.php">click here</a>.
        </CENTER>
    <BODY>
</HTML>

Explanation: The file is started with HTML tags to show basic information. In the middle of web page, with the start of php tag, we used session_start() function to start the a new session and in next line assigned dollar variable a value. We closed the file information and link to the next file.


--------------------------------
FILE 2 - phpsessionret.php
--------------------------------


Code :

<HTML>
    <HEAD>
        <TITLE>
            Retrieving data in sessions
        </TITLE>
    </HEAD>

    <BODY>
        <CENTER>
            <H1>
                Retrieving data in sessions
            </H1>

            <?php
                session_start();

                if(isset($_SESSION["dollar"])){
                    echo "Welcome! The dollar exchange price is " . $_SESSION['dollar'];
                }
            ?>
        </CENTER>
    <BODY>
</HTML>

Explanation: In second file we again started code with HTML tags and showed information to the user. With the start of PHP tag, we used the session_start() function. The if statement is used to check if the variable dollar exists or not. If the variable dollar exists a message with stored value of dollar will be displayed on user screen with the use of echo.

So, in this tutorial you learned how to use session and how to retrieve stored values using session variables between multiples files.
Please do share your feedback and comments in our forum which can be accessed from http://forum.phpreg.com

We are coming up soon with exciting new tutorials! Please stay tuned!
 
< Prev   Next >

Who's Online

We have 9 guests and 16 members online
  • NefOstins
  • arrohawdolo
  • AddemoRegoMom
  • ritachkagubina
  • phoniantUtite
  • Rakuvinina
  • Canoraxy
  • sweamepaice
  • Bumboxbarash
  • atteftosy
  • duffallolve
  • reflexxX
  • Rissiomal
  • toomegema
  • UntotsUttetle
  • VMMark

Sponsors