sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Anant
Forum Commoner
Posts: 66
Joined: Wed Jul 14, 2010 11:46 am

sessions

Post by Anant »

I have created a form in a page A.php with various text fields like name, address etc and image button act as submit.

On pressing the submit(image button) - i go to B.php where i convert all the post values to session using --

Code: Select all

if(isset($_POST)) 
{
  foreach($_POST as $key => $value)
  {
     $_SESSION["key"] = $value;
  }
}

Now the above code creates so many unnecessary sessions like -
currentPage
Submit_x
Submit_y
Submit
Submitted
submitted etc

n then i have a problem while am inserting data to the database as field doesn't exist in database then.
So i have to unset each of the unwanted session before inserting the data like -

Code: Select all

 unset($_SESSION['currentPage']);
i don't think it's a good way...also sometime i have set a session again in page like in few pages i have to say -

Code: Select all

if (!isset($_SESSION['country']))
{
 $_SESSION['country'] = $_POST['country']
}
which is not again a best way.

I thought once you have a form and you start a session and convert all the post values to session - it exist till you destroy the session at the end of the last page.

Please let me know how can i improve sessions or am i doing it right ?

Thanks
Anant
Forum Commoner
Posts: 66
Joined: Wed Jul 14, 2010 11:46 am

Re: sessions

Post by Anant »

Any thoughts ??
Post Reply