www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: How do you use PHP to get the address of the current file?

  1. #1
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    1,592

    How do you use PHP to get the address of the current file?

    How do you use PHP to get the address of the current file?
    Windows XP SP2 - theme: Thallos
    AMD Athlon 64 X2 4600+ | ASUS M2N32-SLI Deluxe | 2 * 1024 PC2-6400 Mushkin DDR2-800 | eVGA GeForce 6800XT 256MB | Creative Sound Blaster X-FI Music
    5 * 320GB Seagate Barracuda SATA-II 3Gb/s in RAID 5 | Lite-On 16x DVD-RW | Mitsumi 7-in-1 Floppy drive and card reader
    Samsung SyncMaster 204B 20" TFT LCD | Logitech G15 Keyboard | Logitech G7 Mouse | Seasonic PC160SK Headset

  2. #2
    Join Date
    May 2003
    Location
    London, UK
    Posts
    327
    Many ways, my friend, though it rather depends what you mean by 'address'. There's plenty of inbuilt variables you may wish to inspect:

    PHP Code:
    $_SERVER['PHP_SELF'];
    $_SERVER['PATH_TRANSLATED'];
    $_SERVER['REQUEST_URI']; 
    here's the relevant manpage

    http://uk.php.net/reserved.variables

  3. #3
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Okay, is there one that gives the document root - not $_SERVER["DOCUMENT_ROOT"] - without the script name?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  4. #4
    Join Date
    Aug 2003
    Posts
    1,576
    getcwd() doesn't do that?

  5. #5
    Join Date
    Aug 2003
    Location
    In my house
    Posts
    4,004
    Is there any way to get the current URL?
    Thousand different paths
    So many sterile ends
    I chose the Devil's path

    Never shall the sun kiss my face
    And caress me with it's burning light
    For I dwell in the shadows
    And sleep side by side with death

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by Paul Jr
    Is there any way to get the current URL?
    I think it's $_SERVER["SCRIPT_NAME"].
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  7. #7
    Join Date
    May 2003
    Location
    London, UK
    Posts
    327
    yeah thats

    PHP Code:
    $_SERVER['REQUEST_URI']; 
    i think i mentioned that

  8. #8
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    1,592
    What I want to do is set a variable as the url of the current page, then carry that value from one page to another and make a link to that varible by using:
    PHP Code:
    print("<a href='$theurl'>Some text</a>"); 
    -Dan
    Windows XP SP2 - theme: Thallos
    AMD Athlon 64 X2 4600+ | ASUS M2N32-SLI Deluxe | 2 * 1024 PC2-6400 Mushkin DDR2-800 | eVGA GeForce 6800XT 256MB | Creative Sound Blaster X-FI Music
    5 * 320GB Seagate Barracuda SATA-II 3Gb/s in RAID 5 | Lite-On 16x DVD-RW | Mitsumi 7-in-1 Floppy drive and card reader
    Samsung SyncMaster 204B 20" TFT LCD | Logitech G15 Keyboard | Logitech G7 Mouse | Seasonic PC160SK Headset

  9. #9
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by samij586
    getcwd() doesn't do that?
    Kind of, but not exactly what I was looking for. Some manipulation, but I guess that's one way you could do it.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  10. #10
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by DanieLTomaS
    What I want to do is set a variable as the url of the current page, then carry that value from one page to another and make a link to that varible by using...
    I have a habit of using sessions.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  11. #11
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    1,592
    Originally posted by Jona
    I have a habit of using sessions.
    How do I do this? I am developing a comment script for my site, and this is the last thing I need, so I really need to know!
    -Dan
    Windows XP SP2 - theme: Thallos
    AMD Athlon 64 X2 4600+ | ASUS M2N32-SLI Deluxe | 2 * 1024 PC2-6400 Mushkin DDR2-800 | eVGA GeForce 6800XT 256MB | Creative Sound Blaster X-FI Music
    5 * 320GB Seagate Barracuda SATA-II 3Gb/s in RAID 5 | Lite-On 16x DVD-RW | Mitsumi 7-in-1 Floppy drive and card reader
    Samsung SyncMaster 204B 20" TFT LCD | Logitech G15 Keyboard | Logitech G7 Mouse | Seasonic PC160SK Headset

  12. #12
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by shimon
    PHP Code:
    $_SERVER['REQUEST_URI']; 
    You didn't quote anyone, but if you were talkin' to me, that variable changes depending on the page requested - my purposes would need something that never changes.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  13. #13
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by DanieLTomaS
    How do I do this? I am developing a comment script for my site, and this is the last thing I need, so I really need to know!
    Well if you only need it once, then you could use $_GET variables - might be easier.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  14. #14
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    1,592
    Originally posted by Jona
    Well if you only need it once, then you could use $_GET variables - might be easier.
    Ok, so is that something like this?
    The main page(which will go to the next page when the form is submitted):
    PHP Code:
    $theurl 
    $_SERVER['REQUEST_URI']; 
    The page I have the link on:
    PHP Code:
    $theurl $_GET['theurl'];
    print(
    "<a href='$theurl'>Some Text</a> 
    Or wait a minute. Since I'm using a form on the first page, would it be better just to store the url in a hidden input element, and use $_REQUEST['hiddenelement'] ?
    Windows XP SP2 - theme: Thallos
    AMD Athlon 64 X2 4600+ | ASUS M2N32-SLI Deluxe | 2 * 1024 PC2-6400 Mushkin DDR2-800 | eVGA GeForce 6800XT 256MB | Creative Sound Blaster X-FI Music
    5 * 320GB Seagate Barracuda SATA-II 3Gb/s in RAID 5 | Lite-On 16x DVD-RW | Mitsumi 7-in-1 Floppy drive and card reader
    Samsung SyncMaster 204B 20" TFT LCD | Logitech G15 Keyboard | Logitech G7 Mouse | Seasonic PC160SK Headset

  15. #15
    Join Date
    May 2003
    Location
    London, UK
    Posts
    327
    You didn't quote anyone
    Hmm now I understand that post count

    But, no - I was taking to the guy who originally asked the question. The idea of the 'address' was vague and so I made a couple of suggestions and then pointed him towards the manual. I'm not sure where sessions come into it, unless you pass session IDs through the query string...and I'm pretty sure you wouldn't do that

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles