redirection

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
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

redirection

Post 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?
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post by Czar »

...anyone?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

sorry, but what is wrong with what you had?

Code: Select all

header("Location: ????????");
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post 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?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Code: Select all

javascript:back(1)
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Sami wrote:

Code: Select all

javascript:back(1)
Is it not history.go(-1); ?
For support with netscape?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

it is, Inter

Code: Select all

javascript.history.go(-1)
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

$HTTP_REFERER
depends whether you want to use client side or not.
Last edited by Wayne on Thu Jun 19, 2003 5:13 am, edited 1 time in total.
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post 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...)
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post 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.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

patrikG wrote:it is, Inter

Code: Select all

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


Late nite Q answering = bad :wink:
Post Reply