"Sims" <si*********@hotmail.com> schrieb im Newsbeitrag
news:c6************@ID-162430.news.uni-berlin.de...
Hi,
I have a few 'secure' area where the user needs to log-in b4 they can make
view it.
I know how to redirect them to the login page but how can I return them to
the page they were?
if I get the path ...and save it, (in a cookie or in MySQL ).
$ReturnUrl = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
the path is relative to the root directory,
(http://uk.php.net/reserved.variables).
And then try and use it (b4 all the headers are sent).
header( 'refresh: 20; url='.$ReturnUrl );
It does not work properly, ( the query strings is truncated). if I place
it in quotes then the system adds http:\\ in the string.
What is the best way to return to a page full path, (including the query
string).
Many thanks Sims
I usually do things like that without a login page but by including the
login form into every page that requires login:
<?php
$logged = false;
if(isset($_POST['login'])) {
if([check for correct username and password here]) {
[write cookie here];
$logged = true;
}
else {
$message = "Incorrect login, try again!";
$logged = false;
}
}
else if([check for cookie]) {
$logged = true;
}
?>
<html>
<head>
</head>
<body>
[put navigation or whatever comes before the contents here]
<div id="contents">
<?php
if(!$logged) {
if(isset($message)) echo "<p><strong>".$message."</strong></p>";
include("myloginform.php");
}
else {
?>
[put page contents here]
<?php
}
?>
</div>
[put footer or whatever comes after the contents here]
</body>
</html>
Like that you don't have redirection problems, and the user that does not
have access to the protected area will not be taken out of his navigation
flow.
HTH
Markus