Page 1 of 1

redirection

Posted: Thu Jun 19, 2003 3:56 am
by Czar
How?

File auth.php validates vars submitted by form from different pages and validates user. I want it to redirect immediately after validation back to that page where vars were submitted.

like...

Code: Select all

<?php
if(mysql_num_rows($authquery) != 0)) {
  header("location:???????");
} else {
  header("location:???????&message=unauthorized");
}
?>
How to do this the easy way?

Posted: Thu Jun 19, 2003 4:37 am
by Czar
...anyone?

Posted: Thu Jun 19, 2003 4:40 am
by Wayne
sorry, but what is wrong with what you had?

Code: Select all

header("Location: ????????");

Posted: Thu Jun 19, 2003 5:01 am
by Czar
i mean i need to determine where tahat post came from. Say if u logged in at page called index01.php, the auth.php should move you back to index01.php after validation with, or without error messages. Same goes for any other page. Login check and form are a function, which is called at every page. So i cannot just put one page to header()-function, therefore it would always redirect to same page regardless of the page u came from.

Did this clear it out?

Posted: Thu Jun 19, 2003 5:02 am
by m3mn0n

Code: Select all

javascript:back(1)

Posted: Thu Jun 19, 2003 5:08 am
by []InTeR[]
Sami wrote:

Code: Select all

javascript:back(1)
Is it not history.go(-1); ?
For support with netscape?

Posted: Thu Jun 19, 2003 5:10 am
by patrikG
it is, Inter

Code: Select all

javascript.history.go(-1)

Posted: Thu Jun 19, 2003 5:11 am
by Wayne

Code: Select all

$HTTP_REFERER
depends whether you want to use client side or not.

Posted: Thu Jun 19, 2003 5:12 am
by Czar
there's a little flaw with that one... when it redirects back, the target page still throws login form 'cause page has not refreshed, and therefore couldn't yet access session vars set by auth.php (like $_SESSION['login'] = true). It would be a little bit confusing for user.

(this would go with javascript...)

Posted: Thu Jun 19, 2003 5:34 am
by Czar
So, i can do that with HTTP_REFERER...

Code: Select all

<?php
$ref = $_SERVER['HTTP_REFERER'];
?>
Var ref would thus be the whole url string:

http://somedomain.com/add.php?a=1&c=0

Could someone remind me how to trim the string so, that var ref would be only like somepage.php.

Posted: Thu Jun 19, 2003 5:40 am
by patrikG
Use parse_url

Example:

Code: Select all

$url=parse_url(http://www.php.net/download-php.php3?csel=br);
$url[scheme] = http
$url[host] = http://www.php.net
$url[path] = /download-php.php3
$url[query] = csel=br

Posted: Thu Jun 19, 2003 2:50 pm
by McGruff
My approach would probably be to pass a value defining the previous page in a hidden form field. Referrer might not always be available.

Posted: Thu Jun 19, 2003 7:43 pm
by m3mn0n
patrikG wrote:it is, Inter

Code: Select all

javascript.history.go(-1)
lol, sorry.


Late nite Q answering = bad :wink: