Jump to content

Archived

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

ajsuk

PHP Include Linking (with subdomains)

Recommended Posts

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.

Share this post


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

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:
[code]<?php
$domainParts = explode(".",$_SERVER['HTTP_HOST']);
if($domainParts[0] == "football"){
$pageid = "baseball";
include("filename.php");//the filename of the page at http://sports.com
}
?>[/code]

Share this post


Link to post
Share on other sites
[quote author=micah1701 link=topic=99835.msg393412#msg393412 date=1152326670]
although, why do you want people looking for football to go to a baseball page?
[/quote]

hehe, yeah, bad example...

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[code]<?php
echo file_get_contents("http://sports.com/?pageid=baseball");
?>[/code]

Share this post


Link to post
Share on other sites
hehe, well thats much more simple, and works! Thankies very much!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.