Jump to content


Photo

PHP Include Linking (with subdomains)


  • Please log in to reply
8 replies to this topic

#1 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 08 July 2006 - 12:42 AM

Hey there, as you'll guess from my post count I'm as noob as they come but I'll try to be as clear as pos. ;)

I've recently started getting in to learning PHP and have modified my website to work using the php include linking functions...
I managed to get it working well but as soon as I tried to use it with my subdomains I hit a brick wall.  :(

If you imagine my website is sports.com. Here is what I'd like to do:

If somebody visits http://football.sports.com, I would like them to be redirected to http://sports.com?pageid=baseball BUT without the new address being visible, so http://football.sports.com still appears in their browser address bar.
Is this posible?

Thanks in advance for any help you can give!

Andy.

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 08 July 2006 - 02:44 AM

the first part is simple enough
<?php
$domainParts = explode(".",$_SERVER['HTTP_HOST']);
if($domainParts[0] == "football"){
header("Location: http://sports.com?pageid=baseball");
}
?>

although, why do you want people looking for football to go to a baseball page?

anyway, the other part will either require using HTML Frames (where you use a 100% sized frame inside your original domain name to make it look like you never left that page)

OR, instead of forwarding to the new page altogether, use an include() in your PHP code.

on the page found at football.sports.com
use the script I gave above but change it like this:
<?php
$domainParts = explode(".",$_SERVER['HTTP_HOST']);
if($domainParts[0] == "football"){
$pageid = "baseball";
include("filename.php");//the filename of the page at http://sports.com
}
?>


"Confidence in the face of risk."

#3 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 08 July 2006 - 03:09 AM

although, why do you want people looking for football to go to a baseball page?


hehe, yeah, bad example...

But anyway thanks very much for the speedy reply, will give it a try and get post back.  ;)

#4 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 08 July 2006 - 01:02 PM

Ok I tried the second example but without much success.  :(

I changed the "football" subdomain and the "baseball" pageid to what they really needed to be.
Then changed the "filename.php" to "index.php" which is what the filename is there, ofcourse, but this didn't work. :(

I guessed I'd perhaps have to put in the full URL or Path to the index file... Both of these did display the index.php file but it didn't set the pageid to "baseball". Any idea what could be wrong?

Thanks again.


#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 08 July 2006 - 01:58 PM

<?php
echo file_get_contents("http://sports.com/?pageid=baseball");
?>


#6 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 08 July 2006 - 02:32 PM

hehe, well thats much more simple, and works! Thankies very much!

#7 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 14 July 2006 - 03:36 PM

hmm, well while the file_get_contents worked to an extent it doesn't then seem to want to continue on when I link from that page. It justs sticks to what I linked the file_get_contents echo to includ...
Is there a better way to do this, anyone?

Thanks again for any help.

#8 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 14 July 2006 - 09:41 PM

any way at all?  ???

#9 ajsuk

ajsuk
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 17 July 2006 - 08:17 PM

*bump*  :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users