Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts

    how can I check the url?

    Hello,
    Is there a way to check if a user entered www. before the url?
    thanks.

  • #2
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Yes, you can check inside the $_SERVER['SERVER_NAME'] global.

    -Adam
    Why not thank me?

    http://adamsworld.name

  • #3
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    doesn't works.

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    It does work. I just added it into a regular expression.
    PHP Code:
    <?php
    $url 
    $_SERVER['SERVER_NAME'];
    $regexp "^\www+.\.com$";
    if(!
    ereg($regexp,$url)){
      echo 
    "no!";
    }else{
      echo 
    "yes!";
    }
    ?>
    Check the $_SERVER global.
    Last edited by fl00d; 11-25-2007 at 06:31 PM.

  • #5
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    apperantly it doesn't works with sub-domains

  • #6
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Just edit the regular expression. Perhaps you should study PHP a bit more.
    Last edited by fl00d; 11-25-2007 at 06:58 PM.

  • #7
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    I did a test where:
    I tried to echo $_SERVER['SERVER_NAME'] and one time I put the www and the other time I didn't and the result was the same in both of the times and only echoed the url without www
    Last edited by shedokan; 11-25-2007 at 07:05 PM.

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Use $_SERVER['HTTP_HOST'] or $_SERVER['SCRIPT_URI'] if you want the full requested path.

  • #9
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    nope the same thing.

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Awesome. Well, maybe next time you give a useless response why don't you include some diagnostic information that might help us. Information like errors, the code you're using, the value of the variables, the expected result, and the actual result.

  • #11
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Inigoesdr View Post
    Awesome. Well, maybe next time you give a useless response why don't you include some diagnostic information that might help us. Information like errors, the code you're using, the value of the variables, the expected result, and the actual result.
    Wow...

    Shedokan, check out http://us.php.net/reserved.variables. It should have the info you're looking for.

  • #12
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    what I need is one of these:
    PHP Code:
    <?php
    echo $_SERVER['SERVER_NAME'];
    echo 
    '<br>';
    echo 
    $_SERVER['HTTP_HOST'];
    echo 
    '<br>';
    echo 
    $_SERVER['SCRIPT_URI'];
    ?>
    but I can't use them because I'm using a subdomain.
    there is this htaccess script:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^subdomain.domain.com [NC]
    RewriteRule ^(.*)$ http://www.subdomain.domain.com/$1 [L,R=301]'
    but my webhost doesn't supports it yet.

  • #13
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Run this code, and post the output:
    PHP Code:
    echo '<pre>' print_r($_SERVER,1) . '</pre>'

  • #14
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Code:
    Array
    (
        [SCRIPT_URL] => /hello.php
        [SCRIPT_URI] => http://neostar.110mb.com/hello.php
        [HTTP_HOST] => neostar.110mb.com
        [HTTP_CONNECTION] => keep-alive
        [HTTP_ACCEPT] => */*
        [HTTP_REFERER] => http://www.110mb.com/
        [HTTP_ACCEPT_LANGUAGE] => he-il,en-us;q=0.7,ru-RU;q=0.3
        [HTTP_UA_CPU] => x86
        [HTTP_ACCEPT_ENCODING] => gzip, deflate
        [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; MRA 4.10 (build 01952); .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322)
        [HTTP_X_FORWARDED_FOR] => 1.1.1.1
        [PATH] => /usr/local/bin:/usr/bin:/bin
        [SERVER_SIGNATURE] => 
        [SERVER_SOFTWARE] => Apache
        [SERVER_NAME] => neostar.110mb.com
        [SERVER_ADDR] => 195.242.99.87
        [SERVER_PORT] => 80
        [REMOTE_ADDR] => 1.1.1.1
        [DOCUMENT_ROOT] => /www/
        [SERVER_ADMIN] => 110mb.server@gmail.com
        [SCRIPT_FILENAME] => /www/110mb.com/n/e/o/s/t/a/r/_/neostar/htdocs/hello.php
        [REMOTE_PORT] => 62440
        [GATEWAY_INTERFACE] => CGI/1.1
        [SERVER_PROTOCOL] => HTTP/1.1
        [REQUEST_METHOD] => GET
        [QUERY_STRING] => 
        [REQUEST_URI] => /hello.php
        [SCRIPT_NAME] => /hello.php
        [PHP_SELF] => /hello.php
        [REQUEST_TIME] => 1196132170
    )
    I had to delete a few things like my IP and cookies

  • #15
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Every suggestion given holds the url you were looking for in the original question.


  •  

    Posting Permissions

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