1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to get Current Browser URL ?

Discussion in 'PHP' started by ebizaustralia, Feb 5, 2009.

  1. #1
    How can I get the current browser url in PHP ?

    I know a code $_SERVER["HOST"] which is not working.

    Please advice.
     
    ebizaustralia, Feb 5, 2009 IP
  2. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $_SERVER["REQUEST_URI"]
    PHP:
    Also, try
    <?php phpinfo(); ?>
    PHP:
    it will show you all available global variables.
     
    steelaz, Feb 5, 2009 IP
  3. ebizaustralia

    ebizaustralia Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey buddy.
    thanks a lot.

    So this global variable differ in one server to another ?

    $_SERVER["REQUEST_URI"]
    PHP:
    is not working,
    $_SERVER["SERVER_NAME"]
    PHP:
    show me the full path url.

    :D
     
    ebizaustralia, Feb 5, 2009 IP
  4. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, these variables can vary from server to server, that's why most scripts require you to enter full path of your script location during setup.
     
    steelaz, Feb 5, 2009 IP
  5. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Well if you want the exact URL as in the address bar of the browser, you will have to use:
    
    <?php
    $url_in_the_address_bar=$_SERVER['SERVER_NAME']. SERVER['REQUEST_URI'];
    ?>
    
    PHP:
    Many times, it may be possible that an application is using re-written URL, such as
    
    http://www.domain.com/computers/laptops/lenovo
    
    Code (markup):
    The actual PHP script may be hidden behind the URL. In such cases, the hidden URL can be obtained from
    
    <?php
    $hidden_url=$_SERVER['SERVER_NAME']. SERVER['SCRIPT_NAME'];
    ?>
    
    PHP:
     
    rohan_shenoy, Feb 5, 2009 IP
  6. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $url=(!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    Code (markup):
    This is the string i used for finding address bar url.

    Hope it helps!
     
    mehdi, Feb 5, 2009 IP