This is probably something really obvious, but can anyone see a bug in this script?
print "<script language='javascript'>";
if (strlen($redirect) == 0) { $redirect = "members_home.phtml"; }
print "self.location = '" .$redirect. "';";
print "</script>";
All this is supposed to do is find out if $redirect is set in the URL, if it is then redirect them to that page using JavaScript, and if it isn't, redirect them to members_home.phtml. The reason I need this is so that if someone is logging in from a different page, eg the forums, it would be handy to redirect them back to there rather than to members_home.phtml.
Anyone got any suggestions? There's no syntax error that I know of, but it just doesn't work a lot of the time.
[SOLVED] Redirect from string in URL
Moderator: General Moderators
-
MarbleKittyKat
- Forum Newbie
- Posts: 5
- Joined: Sat Feb 14, 2004 7:57 am
-
MarbleKittyKat
- Forum Newbie
- Posts: 5
- Joined: Sat Feb 14, 2004 7:57 am
Well the thing is I use globals on other pages and it works ok.
I tried changing the script anyway to
print "<script language='javascript'>";
$redirect = $_GET['redirect'];
if (strlen($redirect) == 0) { $redirect = "members_home.phtml"; }
print "self.location = '" .$redirect. "';";
print "</script>";
But it made no improvement, it still goes to members home..
Thanks though.
I tried changing the script anyway to
print "<script language='javascript'>";
$redirect = $_GET['redirect'];
if (strlen($redirect) == 0) { $redirect = "members_home.phtml"; }
print "self.location = '" .$redirect. "';";
print "</script>";
But it made no improvement, it still goes to members home..
Thanks though.
Why don't use just use PHP or HTML to do the redirecting for you?
I am assuming you are passing a URL like this to redirect:
http://www.yoursite.com/redirect.php?redirect=home.php
If you do this, you can either redirect using PHP (This must be done before anything is outputted to the browser, whitespace and text included!)
Or just use an HTML meta refresh to do it:
The content="0 part is how many seconds to wait before redirecting.
I am assuming you are passing a URL like this to redirect:
http://www.yoursite.com/redirect.php?redirect=home.php
If you do this, you can either redirect using PHP (This must be done before anything is outputted to the browser, whitespace and text included!)
Code: Select all
<?php
$redirect = $_GET['redirect'];
header("Location: $redirect");
?>Code: Select all
<meta http-equiv="refresh" content="0; url=<?php echo $_GETї'redirect']; ?>";-
MarbleKittyKat
- Forum Newbie
- Posts: 5
- Joined: Sat Feb 14, 2004 7:57 am