Solved

Passng SID in the URL

Posted on 2004-04-05
5
174 Views
Last Modified: 2006-11-17
How do you pass the 'same' Session ID number from one page to another when using forms several times on consecutive pages?

I have no problem passing the SID using a href link from page to page.

I have no problem passing the SID from the 'first page' when submitting a form as below:

      if (isset($_POST['submit']))
      {
            
            header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])."/example_page.php?". SID );
            exit();
      }

But when I come to use another form on another page a new SID is passed and my orginal one is lost when the form is  submitted and all my variables are lost?????

I hope this makes sense.

Would be grateful for your help,

Beam.
0
Comment
Question by:Beam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:CosminB
ID: 10757618
send it in a hidden field:
try this:
echo '<input type="hidden" name="',session_name(),'" value="',session_id,'">';
0
 
LVL 2

Expert Comment

by:ElForesto
ID: 10761261
I would imagine that the session would be set server-side, so you shouldn't have to do much beyond session_start() and setting the session variables. Have you tried this scenario? It should be pretty much transparent.
0
 

Author Comment

by:Beam
ID: 10764367
I have just worked it out and thought you guys might want to know for future reference. Basically when you validate a form you post back to it's self, when the submit button is pressed. Please see example below:

<form action="<?php echo $SERVER['PHP_SELF'] ?>" method="post">

But when passing SID through the URL every single link has to pass it otherwise a new SID is produced. I forgot that my forms posted to them selves for validation reasons. I changed the code above to this:

<form action="<?php echo $_SERVER['PHP_SELF']."?". SID  ?>" method="post">

Now the session_id is the same for every page.

Thank you for your time.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12685500
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question