By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

How can i get my current full path? (and use it in the header)

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Attempting to reach the Kolinahr, Sims wrote:
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


$_SERVER["HTTP_REFERER"] might be what you are looking for.

/Andreas

--
#Peace and long life ...
Registeret Linux user #292411
Jul 17 '05 #2

P: n/a
>
$_SERVER["HTTP_REFERER"] might be what you are looking for.

/Andreas


According to the manual that value might not be set. So I cannot rely on it.

"HTTP_REFERER

The address of the page (if any) which referred the user agent to the
current page. This is set by the user agent. Not all user agents will set
this, and some provide
the ability to modify HTTP_REFERER as a feature. In short, it cannot really
be trusted."

http://uk.php.net/reserved.variables

Sims
Jul 17 '05 #3

P: n/a
"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
Jul 17 '05 #4

P: n/a
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


Thanks all for the replies,

Just as an aside, the reason my header(... ) was not working was because I
was replacing the '&' with the html equivalent &amp;

Sims
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.