Find the answer to your Linux question:
Results 1 to 4 of 4
I am not familiar with PHP, just the basic... very basics! Could someone tell me what this code would do and if the syntax is all correct. Thanks Code: <?php ...
  1. #1
    Linux Enthusiast flipjargendy's Avatar
    Join Date
    Aug 2004
    Location
    Xanadu, Titan, Saturn
    Posts
    610

    Question Whta does this PHP code do... and is it correct?

    I am not familiar with PHP, just the basic... very basics! Could someone tell me what this code would do and if the syntax is all correct.

    Thanks

    Code:
    <?php
     $ip = getenv("HTTP_HOST");
    
       if ($ip  == "www.website.com" or $ip == "website.com")
        {
    
         Header("Location: website/index.html");
    
         exit;
    
        }
    
    ?>
    
    <?php
    
       if ($_GET['server'] == true)
       {
    
           phpinfo();
       
        }
    
    ?>
    
    //Not sure why this is here.
    <a href='http://anotherWebsite.com'>Click Here!</a>
    Running Linux Since 2001®
    Registered Linux User #430868 - Since 9•12•06

  2. #2
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    The first block redirects requests for www.website.com or website.com to the index.html file (in case the Web server doesn't do it automatically, which it should if it's configured right).

    The second block looks to see if the URL includes something like "?server=true" tacked onto the end, and if so, shows a page of information about the installed version of PHP.

    The last line would be shown if none of the above is true (i.e., the user got there by some means other than navigating to www.website.com or website.com, and there's no "?server=true" in the URL).

    As far as I can tell, the syntax is correct. You might want a second opinion, since I'm just going off memory and limited understanding (can't test it from where I am).
    Stand up and be counted as a Linux user!

  3. #3
    Linux Enthusiast flipjargendy's Avatar
    Join Date
    Aug 2004
    Location
    Xanadu, Titan, Saturn
    Posts
    610
    I wasn't sure exactly sure if that's what it would do. You answered my question! Thanks!
    Running Linux Since 2001®
    Registered Linux User #430868 - Since 9•12•06

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    That's basically right, though it should be noted that because the second if doesn't have an exit, if you go to something like www. foo .com?server=true, the link would still show.

    Also note that because you're using '==' and not '===', any true value will work in that second if. Therefore, ?server=a would work, etc. '===' would not work in this case, because (as far as I know), you cannot send in a PHP true value through GET.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...