I do not want to display the ?=data when I echo

Discussion in 'PHP' started by mikeonthebeach, Sep 10, 2009.

  1. #1
    I am using the following code to grab the url:

    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }
    Code (markup):
    Then I can echo on my page the url by using:


    <?php echo curPageURL();?>
    Code (markup):

    But I just realized that I need to modify this because if someone comes to my site with an for example mydomain/mypage.php?=data

    Then the url displayed on my page displays:

    mydomain/mypage.php?=data

    I do not want to display the ?=data I really do not want to display the ? and including anything at all after it.

    That "data" part could be anything so I only want to display mydomain/whatevermypageis.php and nothing else

    How could I do this?

    I appreciate your help

    Thanks

    Mike
     
    mikeonthebeach, Sep 10, 2009 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    This one will deal more on .htaccess, mod_rewrite.
     
    bartolay13, Sep 10, 2009 IP
  3. mikeonthebeach

    mikeonthebeach Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply.

    Yes I can see how that would work but have places in my page where I do need to echo the whole string with the ?data= on the end.

    I am really looking for a way to echo the url but a cleaned up version of the url. Is it possible to strip ? and everything after it? when I echo the url?

    Thanks
     
    mikeonthebeach, Sep 10, 2009 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    instead of strip, use parse_url
     
    bartolay13, Sep 10, 2009 IP
  5. mikeonthebeach

    mikeonthebeach Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's cool, just what I needed, thanks for your help.

    Regards

    Mike
     
    mikeonthebeach, Sep 10, 2009 IP