sharey Posted June 23, 2007 Share Posted June 23, 2007 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 https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/ Share on other sites More sharing options...
pocobueno1388 Posted June 23, 2007 Share Posted June 23, 2007 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 https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280623 Share on other sites More sharing options...
sharey Posted June 23, 2007 Author Share Posted June 23, 2007 thanks, Ive tired the following and it doesnt work (just made it up, have no idea what im doing). <?PHP $ref = getenv('HTTP_HOST'); echo $ref; if($ref == 'dn2.com') { header ('http://www.google.com') } else header ('http://www.yahoo.com') } ?> does this go in the header? I'll try yours too Link to comment https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280624 Share on other sites More sharing options...
pocobueno1388 Posted June 23, 2007 Share Posted June 23, 2007 Well, your using the header function wrong. www.php.net/header I have also never seen this "getenv('HTTP_HOST')"....so I couldn't tell you if that was valid or not. Also, your missing a bracket after your "else" clause. Link to comment https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280626 Share on other sites More sharing options...
sharey Posted June 23, 2007 Author Share Posted June 23, 2007 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 https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280634 Share on other sites More sharing options...
sharey Posted June 23, 2007 Author Share Posted June 23, 2007 Oh, and apparently, getenv() gets an environmental variable such as the current URL. Link to comment https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280635 Share on other sites More sharing options...
pocobueno1388 Posted June 23, 2007 Share Posted June 23, 2007 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 https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280639 Share on other sites More sharing options...
JasonO Posted June 23, 2007 Share Posted June 23, 2007 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 https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280641 Share on other sites More sharing options...
sharey Posted June 23, 2007 Author Share Posted June 23, 2007 Thanks all, that helps. I'll get back to you with a success story soon Have a great night. Link to comment https://forums.phpfreaks.com/topic/56802-redirect-to-specific-page/#findComment-280646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.