How to know the address of webpage

Discussion in 'PHP' started by interval, Oct 15, 2007.

  1. #1
    Hi,

    I hope I'll be able to explain what I want.

    I have a webpage, say http://www.mydomain.com/page1.php/ .
    What code (command) to insert in page's code to find the address of page?

    This need to know the addres of page is common for many other webpages, this is the reason I want to use a php script that can make it on its own.

    Advanced thanks for your time and attention
    Interval
     
    interval, Oct 15, 2007 IP
  2. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi,

    you can use the following:
    
    $scripturl = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"];
    
    PHP:
     
    theOtherOne, Oct 15, 2007 IP
  3. interval

    interval Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks,

    That means finally $scripturl will store
    http://www.mydomain.com/page1.php/

    Am I right?
     
    interval, Oct 15, 2007 IP
  4. Invent

    Invent Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes that is correct :)
     
    Invent, Oct 15, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Not quite.

    $_SERVER['SCRIPT_NAME'] holds the name of the current script, but not the actual query string or final slash (as it shows in your URL).

    You may want to use $_SERVER['REQUEST_URI'] instead. (which will hold anything after your server name to the end of the query string).
     
    nico_swd, Oct 15, 2007 IP
  6. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I agree with nico_swd.
     
    undir, Oct 15, 2007 IP
  7. interval

    interval Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you very much to all of you
     
    interval, Oct 15, 2007 IP
  8. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #8

    That's right... but it can also be a problem, if you want to call the same script, passing different arguments ;)
     
    theOtherOne, Oct 15, 2007 IP
  9. le_gber

    le_gber Peon

    Messages:
    28
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    le_gber, Oct 15, 2007 IP