Still Problems understanding $_SESSION variables...

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 14
Joined: Mon Apr 22, 2013 4:00 am

Sun Apr 28, 2013 7:48 am

I'm having problems with the $_SESSION code.
I can't retrieve the info on the next page.

After looking at the manual (which I think lacks enough examples / explanation) I came to this:

if (empty($_SESSION['count'])) {
$_SESSION['count'] = 1;
} else {

<form enctype="multipart/form-data" method="POST" action="ads.php?<?php echo $_SESSION["count"]; ?>" />
<input type="hidden" name="PHPSESSID" value="<?php echo $_SESSION["count"]; ?>" />
Name:<input type="text" name ="name" /><br />
Book:<input type="text" name ="book" /><br />
Subject:<input type="text" name ="subject" /><br />
Price (CAN):<input type="text" name ="price" /><br />
Description: <br /><textarea cols="40" rows="5" name="description">
</textarea><br />
Click to upload:<input type="file" name="pix" /><br />
<input type="submit" name="Upload" value="Upload Picture" />
I managed to get the ID to send in a link to the other page.

But on the next page, when I write:
echo "<b>Name: </b>" . $_SESSION['name'] . "<br />";

How do I retrieve the info from the URL using $_SESSION? Also how do I generate the proper text from $_SESSION using the ID from the link.

I'm open to anything you have in mind.

User avatar
php-forum Active User
php-forum Active User
Posts: 314
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI

Sun Apr 28, 2013 11:18 am

I really don't know what you trying to do, but I think your making $_SESSION harder that it really needs to be.

First treat it like any other kind of variable with the exception that session_start(); has to go before $_SESSION in the file.

A quick example : On one page (Normally the Login Page) you would where you put the information into the $_SESSION variable. Example I create a token variable using $SESSION like this $_SESSION['action_token'] = generate_secure_token(); (This is in my login.php file)

Then I retrieve I will retrieve it in my members.php file like this <input type="hidden" name="action_token" value="<?php echo $_SESSION['action_token']; ?>">

At the top of the file I have something like if (isset($_POST['action_token']) && isset($_SESSION['action_token']) && $_POST['action_token'] == $_SESSION['action_token']) {...more code

The thing is session_start(); always comes before $_SESSION and one security note about $_SESSION never never pass sensitive data with it. For instance in my login.php file I have unset($row['password']); just to make sure the password doesn't somehow get into my $_SESSION Variable.

Post Reply