Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Using $_GET to get php page

    Was just wondering if someone could help me with this regex. Or in fact, there may be another thing i can use that i'm not aware of that's simpler than that - i dunno!

    anyway, using multiple pages on my website with the same code used for alternating NEXT and PREV between pages etc. I'm looking to use $_GET to scan the url to find out which specific .php page is currently displaying, in order to copy it into the link file.

    eg.

    Code:
    www.mysite.com/smiles.php?page=1
    so i need it to detect "smiles.php" or just "smiles" in order for me to have code for next page as:

    Code:
    echo '<a href="/'.$page_name.'.php?page=2">Next</a>
    The only reason i ask is that I want to essentially not have to alter the code for every single different type of page that this PREV/NEXT type of code will be used for on my website. If it can just call the name of the php file, define it as a variable like $page_name, would make life so easy.

    Any thoughts?

    Cheers!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    __FILE__ is a constant, but that is the relative file (as in, any included file will be the included file name).
    What you want is $_SERVER['SCRIPT_NAME']. $_GET is usable only on querystring values (anything after the ? in the uri). Then, you can use parse_url to separate the parts you're wanting to use.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts
    worked perfectly... but i'd forgotten about the elements AFTER the ? that are specific to different pages (categories/genres etc.)

    let's say i make it more difficult for you...

    i want to grab everything from the url EXCEPT the "page=1" bit, including everything that comes after the '?', so it's like the whole url except the very last thing which is startrow

    Code:
    www.mysite.com/books.php?cat=10&sub=12&genre=thriller&page=1
    can this be done as easily or would this require an actual regex. if so, can you help me? many thanks in advance again. it's driving me nuts trying to figure it out

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yeah.
    The easiest way is by manipulating the $_GET variable. If its always the same element name (ie: startrow), you can simply run an unset($_GET['startrow']); and if you really want the querystring back, you can use $querystring = http_build_query($_GET);.
    If its the last item in the list and always the last item, you can pop it off the _GET with array_pop($_GET); and then proceeed with the http_build_query or implosion of you're own.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Feb 2008
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i'm a bit unsure as to what each command does exactly. can someone help me with the syntax on this? the startrow will always be at the end of the url.

    Not sure whether to call the url, then seperate the startrow, change the value and implode it back together or not...


  •  

    Posting Permissions

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