Jump to content

Need Help With Short Script


haydenm92

Recommended Posts

I'm new to PHP and I need help with a short script to put on a webpage.

 

Basically I want it to redirect the visitor someplace else if the referrer is blank, and if the referrer is anything else, then just leave them on the page.

 

There are a bunch of smart people around here, I'm sure someone will be able to help me. Any help is greatly appreciated, thanks in advance!

 

Hayden

Link to comment
https://forums.phpfreaks.com/topic/169194-need-help-with-short-script/
Share on other sites

$_SERVER['HTTP_REFERER'] cannot always be trusted but if you pop that code at the top of the page (adding the curly braces for the is statment and then enclose the actual page code in an else statemnt I.e

 

<?php
if($_SERVER['HTTP_REFERER'] != '')
{
header("location: somewhere.php");
exit;
}
else{

// page code to display if referrer does exist




}
?>

Ok, so I just figured out I kinda need the exact opposite.. sorry!!

 

What I need my page to do is look for a specific referring URL. If it see's that referring URL, then it needs to redirect to another page. Otherwise, any other traffic that visits that page can stay there.

 

Sorry I was thinking wrong in my previous posts. So does anyone know how to do this?

if ($_SERVER['HTTP_REFERER'] == 'url_here')
{
    header("Location: place_to_redirect.php");
}

 

As mentioned though, you can't truely depend on HTTP_REFERER to be accurate. If this is something security related I'd perhaps look into another method.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.