Results 1 to 10 of 10

Thread: How do you get the URL?

  1. #1
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default How do you get the URL?

    I need to be able to figre out what the current page is in order to determin the proper path for an external PHP file. How do I capture the URL? (I can figure out the rest).
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, you could use the combination of the $_SERVER variables to figure get this information. An example:

    Code:
    echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    This will display something along the lines of http://yourdomain.com/dir/file.php

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... $_SERVER['REQUEST_URI'] is quicker. That's exactly what was requested, though it would include extra stuff on the end, like get variales (.htm?var=value) and anchors (.htm#pictures).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    But you could use explode to split the url at the ? or #:

    PHP Code:
    $url $_SERVER['REQUEST_URI'];
    $newurl explode("?",$url); 
    So then $newurl[0] would be the url without the get variables. You can do this with anchors, too, by just replacing the "?" with "#"

    But using Testing's solution is probably easier, anyway.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It depends if the get variables are needed. In some cases, those determine how the page functions, like with a site based on a database with articles definied in the url, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Hmm... $_SERVER['REQUEST_URI'] is quicker. That's exactly what was requested, though it would include extra stuff on the end, like get variales (.htm?var=value) and anchors (.htm#pictures).
    No, it wouldn't. Anchors are irrelevant in HTTP requests and aren't included in the URI on the request line (the first line of a HTTP request).
    Mike

  7. #7
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I didn't mean to spark a debat lol. Anyway, thanks! I figured it out and the script works perfect! That right: MY LOGGIN SCRIPT IS FINALLY DONE! Over 1,000 lines-- whew! But you need not think that it runs slowly. Each file is used for different aspects of the script, for instance blocking users. Thanks for all of your help DD. Can't wait until I figure out what my next project will be. . .
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Mike, is that true if it is sent as the url?
    For example, clicking this link:
    <a href="mypage.htm#pictures">click</a>

    I realize it wouldn't be part of the request if it were just on the page, using it as a target to move up or down to a specific section, but I'd think it would be part of it were it included that way. I was under the impression (perhaps just a random guess that I never tested) that you could use the # method to send a value to PHP, much like GET, but just that you would need to code the retrieval yourself (by splitting at '#').

    And... if that is the case, then all the better for using the REQUEST_URI string instead.


    Anyway, glad it's working. Don't worry about starting a debate. We're just discussing/learning. It's a good thing.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, it's entirely client-side.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Mike, is that true if it is sent as the url?
    Yes, that's what I was talking about. You can read for yourself in RFC 2616. You could also test for yourself by changing:

    <a href="mypage.htm#pictures">click</a>
    to:

    HTML Code:
    <a href="mypage.php#pictures">click</a>
    where mypage.php is:

    PHP Code:
    <?php
    header
    ('Content-Type: text/plain');
    echo 
    $_SERVER['REQUEST_URI'];
    ?>
    I was under the impression (perhaps just a random guess that I never tested) that you could use the # method to send a value to PHP, much like GET, but just that you would need to code the retrieval yourself (by splitting at '#').
    No. With other URI schemes, the fragment identifier may actually be significant, but it's not with HTTP.
    Mike

Bookmarks

Posting Permissions

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