Remember variables

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Remember variables

Post by egami » Mon Dec 03, 2012 9:09 am

Do a bit of research on sessions.

www.php.net/sessions

User avatar
Barrikor
New php-forum User
New php-forum User
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: Remember variables

Post by Barrikor » Mon Dec 03, 2012 6:06 pm

Before any output, (Html code, echo(), print() ), call session_start().

Then you can do something like this:

1st page:

Code: Select all

<?php
    session_start();
    
    $food = 'pizza';
    
    $_SESSION['food'] = $food;
?>
2nd page:

Code: Select all

<?php
    session_start();
    
    $food = $_SESSION['food'];

    echo $food; // will print out 'pizza'
?>

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests