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
Share on other sites

So would i just put

 

<?php

if($_SERVER['HTTP_REFERER'] != '')

header("location: somewhere.php");

?>

 

On www.mypage.com

Then if I just type www.mypage.com in the browser I will be redirected to somewhere.php?

 

Is this all correct?

Thx guys!

Link to comment
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




}
?>

Link to comment
Share on other sites

After re-reading your post your logic is backwards, needs to be testing if it's empty, not if it's not empty. Try this:

 

if (!isset($_SERVER['HTTP_REFERER']))
{
    header("Location: someplace.php");
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.