What is wrong with this php code?

Discussion in 'PHP' started by FlexiHost, Jun 10, 2010.

  1. #1
    
    <?php
    
    $urlarray = explode('.', $_SERVER['HTTP_HOST');
    
    $subdom = $urlarray[count($urlarray) - 2];
    
    switch ($subdom)
    {
    case 'subdomain':
    header("Location: location1.html");
    break;
    
    case 'subdomain2':
    header("Location: location2.html");
    break;
    
    default:
    header("Location: index.html");
    }
    
    ?>
    
    Code (markup):
    I am trying to get it to automatically redirect to a different place based on subdomain
     
    FlexiHost, Jun 10, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not just use htaccess with hostname? It would make it easier compared to using Location: index.html and having a index.php there too.
     
    krsix, Jun 10, 2010 IP
  3. FlexiHost

    FlexiHost Member

    Messages:
    236
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #3
    We are wanting to be able to get our members to set their own sub domains by themselves, just thought this would be an easier option for us to impletment on the site.
     
    FlexiHost, Jun 10, 2010 IP
  4. FlexiHost

    FlexiHost Member

    Messages:
    236
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #4
    Also, with the above code in our index file, it is putting it'self into a loop, not sure how to get round that one.
     
    FlexiHost, Jun 10, 2010 IP
  5. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #5

    Don't Place this code in index Files
    Else Remove Index.php and in the default and change it to location9.php and there setup a redirect to the index :)
     
    Last edited: Jun 11, 2010
    roopajyothi, Jun 11, 2010 IP
  6. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #6
    You have a missing (closing) square bracket. That above line should read;

    $urlarray = explode('.', $_SERVER['HTTP_HOST']);
    PHP:
     
    lukeg32, Jun 11, 2010 IP
  7. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #7
    remove
    default:
    header("Location: index.html"); <------- this
     
    gapz101, Jun 11, 2010 IP
  8. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8
    Thats the error.
    As for the not placing in index file, it is not necessary if index.html and index.php are different and index.php is set as default. that should work i guess!
     
    iama_gamer, Jun 11, 2010 IP
  9. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #9
    Yeah right!
    But according to the need he needs to set as the index.php :)
     
    roopajyothi, Jun 11, 2010 IP