Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/13992-php-include-linking-with-subdomains/
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]

[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.  ;)
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.
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.
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.