PDA

View Full Version : Redirect, then back to original page, once!



DRowland
Apr 12th, 2010, 04:04 PM
I need to redirect from the index page to another page, then on click go back to the index, and stay there. I have tried going to a place on the index below the redirect command on index, but that doesn't work. I'm sure there is an easy way to do this. I've always heard the largest problems have the simplest solutions, so now I need one.
Dick

ahayzen
Apr 12th, 2010, 04:23 PM
If you can do PHP then put the code below in the index page. (make sure that the index filename has .php at the end)


<?php
if ($_SERVER['HTTP_REFERER']!="anotherpage.html")
{
header("Location: anotherpage.html");
}
?>


replace anotherpage.html with the address of your second page.

Andy

ahayzen
Apr 12th, 2010, 04:26 PM
You need to put this php code before all of the html code for it to work.

Andy

DRowland
Apr 12th, 2010, 04:28 PM
Thanks for the quick reply.
So, to be sure I understand. Do I change the name of index.htm to index.php?

ahayzen
Apr 12th, 2010, 04:29 PM
yes otherwise the php code won't be executed.

Does your server support php?

ahayzen
Apr 12th, 2010, 04:32 PM
how are you linking back to the index.php on the second page 'anotherpage'?

ahayzen
Apr 12th, 2010, 04:51 PM
Did it work?

DRowland
Apr 12th, 2010, 04:59 PM
I went to the second page, but it happened really fast, and now when I try to go back, it comes right back to the second page, and will not stay on the index. So the problem persists.
My second page is called Memorial. I have the memorial page link going back to an anchor called #memorial on the index, which is below the original auto redirect. but it keeps coming back to memorial page anyway. GRRRRR!

ahayzen
Apr 12th, 2010, 05:00 PM
have you got a link to the page?

DRowland
Apr 12th, 2010, 05:01 PM
here is the language..

<div align="center"><a href="/index.php#Memorial">To continue to Career
Path Inc. website, click here.</a> </div>

ahayzen
Apr 12th, 2010, 05:04 PM
ok change the php code to this


<?php
if ($_GET['referer']!="memorial")
{
header("Location: anotherpage.html");
}
?>


And then change the link to



<a href="/index.php?referer=memorial#Memorial">

DRowland
Apr 12th, 2010, 05:06 PM
and on the index page. I have this language...
<A NAME="Memorial"><font color="#FFFFFF">Welcome Page</font></A>

I think that should take care of it. But since there is no time lag in getting back to the memorial page, I don't know if I am going back to the index page or not. However, I still have the problem, I think, that I am returning to the memorial page instead of staying on index. I think I'm gonna go to a BAR!!

ahayzen
Apr 12th, 2010, 05:09 PM
I think, that I am returning to the memorial page instead of staying on index.

The code above should fix this.

Andy

ahayzen
Apr 12th, 2010, 05:11 PM
you haven't changed the redirect address. It is still set to anotherpage.html

ahayzen
Apr 12th, 2010, 05:11 PM
<?php
if ($_GET['referer']!="memorial")
{
header("Location: memorial.htm");
}
?>


That is what the php code should read.

DRowland
Apr 12th, 2010, 05:15 PM
IT WORKS!!! Now, if you can only tell me how to make it wait about 10 seconds before it redirects, and gives a message to the visitor, and serves coffee and a sweet roll, and tells the visitor to be sure to fasten his/her safety belt and put their trays in the upright and locked position, we would be in perfect condition!! :thumbsup:

ahayzen
Apr 12th, 2010, 05:21 PM
Well you could put a alert box.

change the php to this


<?php
if ($_GET['referer']!="memorial")
{
header("Location: memorial.php?redirect=true");
}
?>


Then you need to change the memorial page to php again, sorry.

And then in the memorial page put.



<?php
if ($_GET['redirect']=="true")
{
echo '
<script type="text/javascript">
alert("You have been redirected");
</script>
';
}
?>


Either put this in the head (by the other javascripts) or at the end just before the ending body tag.

Andy

ahayzen
Apr 12th, 2010, 05:26 PM
Now for your delay

change the php code in the index.php to



<?php
if ($_GET['referer']!="memorial")
{
echo '<meta http-equiv="Refresh" content="10;url=memorial.php?redirect=true">';
}
?>


But you do need to move the php code inside the head.

Andy

ahayzen
Apr 12th, 2010, 05:50 PM
That seems to work!

ahayzen
Apr 12th, 2010, 06:02 PM
I can't do anything about the coffee and the sweet roll though:(

Andy

DRowland
Apr 12th, 2010, 08:12 PM
Andy, I have one more request... I know I'm a real bother..

Is there a way to eliminate the button on the redirect sign, so it just sits for a few seconds and moves on?

DRowland
Apr 12th, 2010, 08:31 PM
Andy, you are a man among men. Thanks a bunch. Now all I have to do is figure out how to show this problem as solved. with my gratitude to you.

ahayzen
Apr 13th, 2010, 10:30 AM
Go over to the first post. Click edit then click go advanced. Then there should be drop down menu to select solved (Should be near the title.)

Andy