1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Website coding question...

Discussion in 'General Scripting Chat' started by true3000, Feb 5, 2011.

  1. true3000

    true3000 Regular Member

    Joined:
    Feb 10, 2009
    Messages:
    291
    Likes Received:
    305
    Occupation:
    making money
    Location:
    United States
    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...
     
  2. true3000

    true3000 Regular Member

    Joined:
    Feb 10, 2009
    Messages:
    291
    Likes Received:
    305
    Occupation:
    making money
    Location:
    United States
    anyone?
     
  3. fyber_optic

    fyber_optic Junior Member

    Joined:
    Sep 21, 2008
    Messages:
    127
    Likes Received:
    94
    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.
     
    • Thanks Thanks x 1
  4. true3000

    true3000 Regular Member

    Joined:
    Feb 10, 2009
    Messages:
    291
    Likes Received:
    305
    Occupation:
    making money
    Location:
    United States
    Your assumption is correct...I am just trying to track down a basis for the php script...no luck yet!
     
  5. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    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.
    }
    ?>
     
    • Thanks Thanks x 3
    Last edited: Feb 5, 2011
  6. true3000

    true3000 Regular Member

    Joined:
    Feb 10, 2009
    Messages:
    291
    Likes Received:
    305
    Occupation:
    making money
    Location:
    United States
    You sir.....ROCK!

    Thanks!
     
    • Thanks Thanks x 1
  7. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    No problem. I updated the first code for texas.mydomain.com...I forgot a forward slash. =P
     
  8. Monrox

    Monrox Power Member

    Joined:
    Apr 9, 2010
    Messages:
    615
    Likes Received:
    579
    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?
     
  9. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    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: Feb 5, 2011