Log in

View Full Version : PHP redirect help



taydu
01-15-2008, 10:25 PM
I'm looking for a php script to redirect all request to the main page before entering the forum.

i.e. if someone type in http://www.dynamicdrive.com/forums/newthread.php or http://www.dynamicdrive.com/forums/showthread.php?t=xxxx or http://www.dynamicdrive.com/forums/

they will be redirect to http://www.dynamicdrive.com/news

and from there the can click on the button "continue" then it will take them to where they requested.

if they request to go to http://www.dynamicdrive.com/forums/newthread.php then when they click continue it will take them their .

and if they see the new page already they can go direct to the forum without seeing it untill the cookie exprires or they close their browser.

search enginee should be exclude so they can index.

i google about php redirection but couldn't find anything :( please help

taydu
01-15-2008, 11:49 PM
i found this code, the only problem it's it block out user that using firewall that doesn't send out third party cookies such as zone alarm (have to turn it off)

can someone help


session_start();
$UR_DOMAIN1 = 'www.google.com';
$UR_DOMAIN2 = 'http://google.com';
$TEN_COOKIE = 'firewall';

if ( strstr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'Googlebot')||strstr($HTTP_SERVER_VARS
['HTTP_USER_AGENT'] ,'msnbot')||strstr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'slurp'))
{}
else{
if( file_exists($firewall) ){ require_once($firewall);}
if((strpos($_SERVER['HTTP_REFERER'], $UR_DOMAIN1) !== 0)) {
if (empty($HTTP_SESSION_VARS['{$TEN_COOKIE}']))
{
if (!empty($HTTP_POST_VARS['{$TEN_COOKIE}']))
{
session_register('{$TEN_COOKIE}');
$HTTP_SESSION_VARS['{$TEN_COOKIE}']='myforum_protection';
header("location: ".$_SERVER['REQUEST_URI']);
exit();
}

if((strpos($_SERVER['HTTP_REFERER'], $UR_DOMAIN2) !== 0)) {
if (empty($HTTP_SESSION_VARS['{$TEN_COOKIE}']))
{
if (!empty($HTTP_POST_VARS['{$TEN_COOKIE}']))
{
session_register('{$TEN_COOKIE}');
$HTTP_SESSION_VARS['{$TEN_COOKIE}']='myforum_protection';
header("location: ".$_SERVER['REQUEST_URI']);
exit();
}

$sform='

HTML CONTENT GO HERE

';
echo $sform;

exit();
}
}
}
}
}

emminar
01-16-2008, 08:36 AM
You could use GET, couldn't you?

taydu
01-16-2008, 08:40 AM
how would i do that ???

TimFA
01-20-2008, 03:00 AM
Or you could shorten the above load of unnecessary junk. Of course (SOME of) its helpful, but not necessarily needed. A simple PHP version:



session_start();
$visit=$_SESSION['visit'];

if ($visit=="yes") {
print("
the page the page
");
}

else {
session_start();
$_SESSION['visit']='yes';

print("
<html>
<head>
<script type=\"javascript\">
window.location='thesite.com/news';
</script>
</head>
<body>
</body>
</html>
");
}


That script (best I can figure) has protection from Google, Yahoo, etc. from seeing this redirect but I can't mess with it as I've never used the functions it uses up there. I miht be able to rig something up with switch, but I don't think ti would work quite the way I'm expecting. Anyways that should work for as long as they are still visiting your site after maybe 10-15 mins of being inactive on your site it will be forgotten.


EDIT: and yes you could use GET.



$visit=$_GET['visit'];

if ($visit=="yes") {
print("
the page the page
");
}

else {
print("
<html>
<head>
<script type=\"javascript\">
window.location='thesite.com/news';
</script>
</head>
<body>
</body>
</html>
");
}


Although you'd need a special link to get back , thesite.com/whatever.php?visit=yes and it could be bypassed.