Website coding question...

true3000

Regular Member
Joined
Feb 10, 2009
Messages
291
Reaction score
307
Alright, so here's the deal...and yes, I have searched high and low and haven't been able to find the solution I am looking for.

I want to create a subdomain such as texas.mydomain.com and when someone visits that site they get redirected to my main domain BUT with a welcome message such as "Hi Texans, welcome to mydomain.com"...

Now when someone enters just mydomain.com it would read as something generic like..."Hi there"...

Anybody know what the appropriate code would be?

And no, it's not a Wordpress site so a wordpress plugin won't work...
 
All you need is a simle php script that would display Hello Texan when the visitor refferer is texas.mydomain.com. I assume you know how to redirect the visitor from the subDomain to your Homepage.
 
All you need is a simle php script that would display Hello Texan when the visitor refferer is texas.mydomain.com. I assume you know how to redirect the visitor from the subDomain to your Homepage.

Your assumption is correct...I am just trying to track down a basis for the php script...no luck yet!
 
At texas.mydomain.com, you need one file:
index.php
PHP:
<?
// Redirects user to main site, with parameter "s" (state) as "tx" (Texas)
header("Location: http://www.mydomain.com/?s=tx");
?>

On your main site, for the entrance page (presumably index.php):
PHP:
<?
// If the "s" (state) parameter isn't set, show generic message
if (!isset($_GET['s'])) {
     echo "Insert generic welcome message."
} else if ($_GET['s'] == "tx") {
     echo "Welcome, Texan..."
}
?>

However, this will get redundant and inefficient for 50 states, if you're doing 50 states. You could store the state codes and other state-specific data in a MySQL database and fetch the data via the state code passed by the "s" parameter. But, if you don't know how to use MySQL, I suggest setting up an array:
PHP:
<?
$states = array(
          "tx" => "Texan",
          "ak" => "Alaskan"
          );

// If the "s" (state) parameter isn't set or the state code doesn't exist in the array (user tampered), show generic message
if ((!isset($_GET['s'])) || (!array_key_exists($_GET['s'], $states))) {
     echo "Insert generic welcome message."
} else {
     $key = $_GET['s'];
     echo "Welcome, " . $states[$key] . "." // Shows "Welcome, Texan." etc.
}
?>
 
Last edited:
Since the thread seems resolved I'll allow myself a hijack for a moment since someone here knows his way with PHP.

Hey artizhay, do you know how to show / hide a server side include based on referrer?
 
Since the thread seems resolved I'll allow myself a hijack for a moment since someone here knows his way with PHP.

Hey artizhay, do you know how to show / hide a server side include based on referrer?
If I understand you correctly, you just use an if statement to determine if the file should be included. So:
PHP:
<?
$ref = $_SERVER['HTTP_REFERER'];
if ($ref == "the_referer_you_want") include ("file-to-include.php");
?>

Or if you want to always include the file, but only show certain portions of it based on the referrer, then:
PHP:
<?
$ref = $_SERVER['HTTP_REFERER'];
if ($ref == "the_referer_you_want")
     include("file-to-include.php");
else
     include("file-to-include.php?correct_refer=no");
?>

And in your include file, there are various ways you could control the output:
PHP:
<?
if (!isset($_GET['correct_refer']))
     echo "This is shown to people with your preferred referer.";
else 
     echo "This is shown to people without your preferred referer.";

if ($_GET['correct_refer'] == "no")
     echo "This is only shown to people without your preferred refer.";
?>
 
Last edited:
Back
Top