Jump to content

Redirect to specific page


sharey

Recommended Posts

Hi, simple question - just dont know the simple answer.

 

I have 2 domain names that point to the exact same directory on a webserver

 

say.. www.dn1.com and www.dn2.com

 

when the user comes from www.dn2.com id like to redirect to page2.php, and if they go to www.dn1.com just go to index.php. So, how can i look at the refering url and then redirect based on it?

 

should be easy, right? I just have no idea what im doing with PHP, but im a fast learner!

 

Thanks in advanced - you're cool.

 

 

Link to comment
Share on other sites

Okay, I'm going to give this a shot.

 

<?php

$refer = $_SERVER['HTTP_REFERER'];

if ($refer == "http://www.dn2.com"){
   header('site.com/page2.php');

} else if ($refer == "http://www.dn1.com"){
   header('site.com/index.php');  
}

?>

 

I have no idea if it will work, a complete shot in the dark. You can try it out though =]

Link to comment
Share on other sites

Good calls.

In that case, are you using it wrong as well since you don't have "Location" in there? Also, it mentions header must be used before any output... is this referring to output within the body tags? If so, am I safe by putting this in the head tags - is that the right spot?

 

I'm pretty sure I had that curly bracket in there, but bumped it before i posted for you.

 

Anyway, I'll try again soon, but I'm on my laptop now and don't know the server credentials to test right now :/

 

Hope to hear back though.

 

Thanks,

 

 

Link to comment
Share on other sites

Woah 0_o I have nooo idea how I forgot to put the "location" in the header tag, stupid me.

 

<?php

$refer = $_SERVER['HTTP_REFERER'];

if ($refer == "http://www.dn2.com"){
   header('Location: site.com/page2.php');

} else if ($refer == "http://www.dn1.com"){
   header('Location: site.com/index.php');  
}

?>

 

And no, don't put this code in the head tag, this should go in between the body tags with the rest of you code.

 

 

Link to comment
Share on other sites

In that case, are you using it wrong as well since you don't have "Location" in there? Also, it mentions header must be used before any output... is this referring to output within the body tags? If so, am I safe by putting this in the head tags - is that the right spot?

 

Yep Location needs to be used, see below. Header must be used before <html> or it will give you an error. The first line should be the start of your header information, and after that your normal HTML tags etc would be used.

 

<?php
header('Location: http://www.example.com/');
?>
<html>

 

http://uk3.php.net/header - Says that if it is put AFTER the <html> tag, it will give an error.

 

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.