index.php and 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
teezilla
Forum Newbie
Posts: 6
Joined: Tue Feb 03, 2009 2:48 pm

index.php and sessions

Post by teezilla »

I'm a novice and I'm trying to use my session to to send me to a new location whenever I return to the site..

This is what I have but It's not doing what expectecd..

<?php


if (!isset($HTTP_SESSION_VARS['session1']) || $HTTP_SESSION_VARS['session1'] != "home_session") {
header ("Location: 1A.php");
}
else
session_start();
if (!isset($HTTP_SESSION_VARS['pg1A']) || $HTTP_SESSION_VARS['pg1A'] != "pg1A") {
header ("Location: 1B.php");
}
else
session_start();
if (!isset($_SESSION['session']) || $_SESSION['session1'] != "1A") {
header ("Location: 2.php");
}
else
session_start();
if (!isset($HTTP_SESSION_VARS['pg2']) || $HTTP_SESSION_VARS['pg2'] != "pg2") {
header ("Location: 3.php");
}
else
session_start();
if (!isset($HTTP_SESSION_VARS['pg3']) || $HTTP_SESSION_VARS['pg3'] != "pg3") {
header ("Location: 4A.php");
}
else
session_start();
if (!isset($HTTP_SESSION_VARS['pg4A']) || $HTTP_SESSION_VARS['pg4A'] != "pg4A") {
header ("Location: 4B.php");
}
else
session_start();
if (!isset($HTTP_SESSION_VARS['pg4B']) || $HTTP_SESSION_VARS['pg4B'] != "pg4B") {
header ("Location: 4C.php");
}
else
session_start();
if (!isset($HTTP_SESSION_VARS['pg4C']) || $HTTP_SESSION_VARS['pg4C'] != "pg4C") {
header ("Location: 5A.php");
}
session_start();
session_unregister("pg4C");
session_destroy();
?>

Please any help would be appreciated..
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Re: index.php and sessions

Post by mchaggis »

First thing would be to remove all references to session_start(); and just place one call to the session_start() function at the top of your script.

Also, you may just wish to use a cookie rather than a session, as the server will clear the session from the server, where as the cookie "should" stay in existence till you decide or the client clears it's cookies.

Hope that helps
teezilla
Forum Newbie
Posts: 6
Joined: Tue Feb 03, 2009 2:48 pm

Re: index.php and sessions

Post by teezilla »

Thank you will try that..
Post Reply