View Full Version : different type of redirect script
scobb7734
12-12-2007, 12:55 AM
HI Everyone,
I have a website (http://www.worstchristmaslights.com) where viewers can vote on the different christmaslight display pictures (each picture is it's own url). After voting they are taken to a thank you screen and then they must click the back button to get back to the picture.
I am looking for a redirect script that will take them right back to the webpage they came from without having to click on the back button.
I've seen several scripts that will redirect to an exact URL but not one that will redirect back to the refering URL.
Any help would be appreciated.
Steve
thetestingsite
12-12-2007, 01:37 AM
If you have access to the php code in rating.php, you could add this line to it so that it redirects back to that site:
header('Location: http://yourdomain.com/'.$_POST['fname']);
or if you want to give it a little while before redirecting, you could use something like the following:
header('Redirect: 3; url=http://yourdomain.com/'.$_POST['fname']);
Be sure to place that before anything gets sent to the browser.
Hope this helps.
scobb7734
12-12-2007, 02:30 AM
Ok, first off, thank you for the help, but...
I've tried putting that snipet in several different places but no success.
Here is the main part of rating.php
<!-- content-wrap starts here -->
<?php include("../sidenav.php"); ?>
<div id="main">
<p style="text-align: center">
<img border="0" src="../images/lights01.gif" width="551" height="46" align="center" style="border-width: 0px">
</p>
<?php
include "header.txt";
?>
<table align=center border=1 style="margin-left: 35px; font-size: 13px; border: #449944 solid 2px;">
<tr>
<td align=center>
<?php
$name = $_POST['fname'];
$rat = $_POST['rate'];
//echo "----$name";
//echo "---------------$rat";
$ser=$_SERVER['HTTP_HOST'];
$ref=$_SERVER['HTTP_REFERER'];
$host= parse_url($ref);
//echo "-------$host[host]-------";
$fname = $name;
$rip = $_SERVER['REMOTE_ADDR'];
$lines = file("./rateval.txt");
$rated = false;
if($ser == $host[host])
{
foreach ($lines as $line_num => $line)
{
//echo $line."<br>";
$firstPos = strpos($line,$rip);
//echo($firstPos);
if(!($firstPos === false))
{
$secPos = strpos($line,$fname);
if(!($secPos === false))
{
//echo($secPos."-".$fname."-".$line);
$rated=true;
break;
}
}
}
if($rated === false && $name!='')
{
$open = fopen("./rateval.txt", "a");
fwrite($open,$fname."****".$rip."####"."0000"."%%%%".$rat);
fwrite($open,"\n");
fclose($open);
}
echo("<div align=left style=\"margin-left: 25px; font-size: 13px; border: #449944 solid 1px; padding: 12px;\">");
include "message.txt";
echo("</div>");
?>
</td>
</tr>
</table>
<?php
include "footer.txt";
}
?>
If I put the new code line anywhere after <?php include("../sidenav.php"); ?> , I get the following type error -
Warning: Cannot modify header information - headers already sent by (output started at /home/.venus/scobb77/worstchristmaslights.com/sidenav.php:59) in /home/.venus/scobb77/worstchristmaslights.com/HRAT/rating.php on line 73
I guess which is why you said to place it before anything was sent to the browser. But if I place it before sidenav.php, nothing happens.
Any suggestions?
thetestingsite
12-12-2007, 04:36 AM
Probably your best bet would be to output a javascript snippet to the browser. Something like the following should work for you:
<script type="text/javascript">
window.location.href='http://yourdomain.com/<?php echo $_POST['fname'];?>';
</script>
Hope this helps.
scobb7734
12-12-2007, 11:27 AM
I thought that was going to do the trick and it did send me right back to my original starting point but it also seemed to clear the voting info. If I take the code out and revote, or re-click on the link to that page, the vote totals return.
Again, thanks so much for the help on this.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.