Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAINTAINING session values 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
How can one keep values obtained in a session, where the user/visitor hops fron page to page?. I don't want to use cookies, or put the values in the URL. Exampl of flow - A user arrives at a menu page, say Menu. They select a page of items to selcect, they select some and the values are kept. The user then returns to the Menu, goes off and selects other items. They either return and go through the process again, or go back to one of the pages and check their selections were correct or go to a send it page - mailto.

A senario - Menu has three pages to select from. Each page has 2 items to enter quantity against. How do I keep values during any permutation until reaching what could be called a checkout page. Regards
 
Sorry sleipnir,

I was reading one of my own!!. About time you had another star.
 
1) Okay, give up. Whats the answer?

"Fetch the session id (see session_id()) then explicitly include that ID in the URL you use with header ('Location:...');


2) Got my session ID.

<?php
session_start();
$ID_sessionid = session_id();
echo "SessionID=: $ID_sessionid<br />";
?>

3) My existing header code

header("Location: Menu1.php");

Make me happy!

Regards

 
PHP will, with trans-sid turned on, modify tags in pages. It will add sufficient code to submit the SID. PHP take output like:

print '<a href="foo.php">bar</a>';

and change it to something like

print '<a href="foo.php?SOMEVARIABLE=SOMEIDVALUE">bar</a>';

You must do the following:[ol][li]Figure out what PHP is, on your installation, using for SOMEVARIABLE[/li][li]Modify your header() so that the SOMEVARIABLE is included in the location specified[/li][/ol]

Just keep in mind that if you use trans-sid for sessions, it is less secure than using cookies, as it is easer to mess up. The PHP online manual chapter titled "Session Handling Functions" introduction ( includes:
URL based session management has additional security risks compared to cookie based session management. Users may send a URL that contains an active session ID to their friends by email or users may save a URL that contains a session ID to their bookmarks and access your site with the same session ID always, for example.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Many thanks,

"PHP will, with trans-sid turned on, modify tags in pages"

In my earlier posting, I said the Hosted site has trans-sid TURNED OFF and say they will not make it active.
I can see the win file, but am not allowed to alter it. Although it is set to on, it's not active as they did not compile PHP with it on.

I have tried this:

This is in the Menu page
<?php
session_start();
$SID = session_id();
echo "SessionID: $SID<br />";
?>


This is in the next page, which should then return
to the Menu page with the same session ID
but it shows a different one!!.

<?php
session_start();
$_SESSION['DB6'] = $_POST['DB6'];
$_SESSION['DB12'] = $_POST['DB12'];
$_SESSION['DB22'] = $_POST['DB22'];

Header ("Location: Menu1.php".$SID);

?>

Any idea why. Also re Session ID in the URL, can I put it in a hidden field, if so how could I do it.

Many thanks
 
try this:
Code:
<?php
session_start();
$_SESSION['DB6'] = $_POST['DB6'];
$_SESSION['DB12'] = $_POST['DB12'];
$_SESSION['DB22'] = $_POST['DB22'];

// your code here (NOTHING PARSED THOUGH!!)
header("HTTP/1.1 301 Moved Permanently"); // to avoid google penalizing you
header("Location: Menu1.php?{$SID}"); // where you want to go!
header("Connection: close");  // fix for IE bug
?>

assuming the logic is correct.

Olav Alexander Mjelde
Admin & Webmaster
 
Thanks Olav,

It go rejected, saying headers had already gone out or words to that effect. However there is no output before the PHP code.

The menu - This is the first page that opens. Menu1.php
<?php
session_start();
$SID = session_id();
echo "SessionID: $SID<br />";
?>

From the menu the next page is selected via click on image.

<td width="197">
<a href="test_sessiona.php">
<img border="0" src="images/product-d321.jpg" width="187" height="126"></a></td>

However, on this page I have:

test_sessiona.php

<?php
session_start();
echo "SessionID: $SID<br />";
?>

BUT no session ID appears echoed on the page?

The final page is Test1.php which takes the values from test_sessiona.php and puts them in variables, and then returns to Menu1.php

Test1.php
<?php
session_start();
$_SESSION['DB6'] = $_POST['DB6'];
$_SESSION['DB12'] = $_POST['DB12'];
$_SESSION['DB22'] = $_POST['DB22'];

// your code here (NOTHING PARSED THOUGH!!)
header("HTTP/1.1 301 Moved Permanently"); // to avoid google penalizing you
header("Location: Menu1.php?{$SID}"); // where you want to go!
header("Connection: close"); // fix for IE bug
?>

This code errors, saying header output already sent, although there is no output HTML before this code.

I think soon I will drop this and just rely on cookies. Thanks for comming back
 
It go rejected, saying headers had already gone out or words to that effect. However there is no output before the PHP code.
When PHP gives the "headers already sent" error, it is always because of output. "Output" includes errors, warnings, and anything, even blank lines, that appear before the first <?php tag.


echo "SessionID: $SID<br />";
That may be because $SID doesn't do anything. You need to reference the constand SID (no dollar-sign).

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks very much. I have called it a day on the subject. I cannot spend more hours joining bits into the code I have pasted on the site getting no clearer or nearer into making a simple task work. I am therefore going to rely on cookies which don't seem to let me down, it works. I could spend many more hours and just waste time. Thanks for the help on the subject. Regards
 
Many thanks,

Yes it was a while back, but I wanted to cover myself against users having cookies turned of. However I put my code on another forum TODAY and someone filled in bits of my code (5 lines) and its working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top