/    Sign up×
Community /Pin to ProfileBookmark

How to reset $_SESSION[‘caller’] ? Need help

I have on each page session code:

[code=php]
if(isset($_SESSION[‘logged’]) or $_SESSION[‘logged’] = TRUE)
{
$_SESSION[‘caller’] = $_SERVER[‘PHP_SELF’];
}
[/code]

After user logs in login page there should redirect him to Home page. But problem is that there is code and it remembers last visited page with
$_SESSION[‘caller’] and it brings him to login page again.

How to reset caller in this case not reseting ALL SESSION VARIABLES
like $_SESSION = array(); ? Please help :rolleyes:

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bokehOct 29.2005 — Maybe you could use one of the following:[code=php]$_SESSION['caller'] = '';
$_SESSION['caller'] = NULL;
$_SESSION['caller'] = FALSE;
$_SESSION['caller'] = 0;
unset($_SESSION['caller']);[/code]
Copy linkTweet thisAlerts:
@toplisekauthorOct 29.2005 — I had in login page code:
[code=php]

if(isset($_SESSION['caller']))
# if we got here from another page, go there
{

header("Location: " . $_SESSION['caller']);

}
[/code]



This caused all the time redirection to login form. I just put away this and it works.

Thanks it works and it is redirected to home page.
Copy linkTweet thisAlerts:
@bokehOct 29.2005 — That is not the problem. The problem is here:[code=php]if(isset($_SESSION['logged']) or $_SESSION['logged'] = TRUE)
{
$_SESSION['caller'] = $_SERVER['PHP_SELF'];
} [/code]

That should just be: [code=php]$_SESSION['caller'] = $_SERVER['PHP_SELF'];[/code] If they need to be logged in to set that variable it is never going to be sent to the login page.
Copy linkTweet thisAlerts:
@toplisekauthorOct 29.2005 — Please confirm me that this will be now O.K.

I have omitted as you told me, but It works ONLY if I omit

also code from LOGIN.PHP (look at login.php) :

I have code for LOGIN:
[code=php]
<?


/* Connect to MySQL-Server */
...


/* Open $db */
...

$user=strtolower($_POST['username']);
$pswr = $_POST['password'];
$crypt_pswr=md5 ($pswr);

$query ="SELECT * FROM users WHERE
username = '$user'
AND " ."
cryptpswr = '$crypt_pswr'";

$result = mysql_query($query) or die("ERROR: " . mysql_error());
if(mysql_num_rows($result) > 0) # we found a match, so set $_SESSION flag:
{
$_SESSION['logged'] = TRUE;
$username=$_POST['username'];
$password=$_POST['password'];

/*this I have to omit and it works:

if(isset($_SESSION['caller']))
# if we got here from another page, go there
{

header("Location: " . $_SESSION['caller']);$loginvalid=1;

}
else
# otherwise go to main page
{
header("Location: home.php");$loginvalid=1;
}
End of what I have to omit*/
}
else
# invalid login, so create error message
{
if ($validation==FALSE && (mysql_num_rows($result)==0))
{
$errorinput="This <b>Username or Password</b> is not valid!<br />"; }
else {}
}
?>
[/code]


and session on login page is:
[code=php]
<?PHP
session_start();

/* I omit as you explained:
if(isset($_SESSION['logged']) or $_SESSION['logged'] = TRUE
and $_SESSION ['guest'] = FALSE or $_SESSION ['guest'] = 0)
{
$_SESSION['caller'] = $_SERVER['PHP_SELF'];
} */

$_SESSION['caller'] = $_SERVER['PHP_SELF'];

if(!isset($_SESSION['logged']) or $_SESSION['logged'] != TRUE)
{
$_SESSION['caller'] = $_SERVER['PHP_SELF'];
header('Location: index.php');
}



?>
[/code]
Copy linkTweet thisAlerts:
@bokehOct 29.2005 — It looks like you got that Login code from [URL=http://www.charles-reace.com/login_article.html]Nogdog's site[/URL] but you are in a muddle about which bit of code should be in which file. Go back to his site and have a read until you understand how you should be using it.
Copy linkTweet thisAlerts:
@toplisekauthorNov 01.2005 — Thanks I will do
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...