Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-26-2009, 11:46 PM   PM User | #1
halifaxer
New Coder

 
Join Date: Feb 2008
Posts: 37
Thanks: 4
Thanked 0 Times in 0 Posts
halifaxer is an unknown quantity at this point
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!
halifaxer is offline   Reply With Quote
Old 03-26-2009, 11:51 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
__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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-27-2009, 12:32 AM   PM User | #3
halifaxer
New Coder

 
Join Date: Feb 2008
Posts: 37
Thanks: 4
Thanked 0 Times in 0 Posts
halifaxer is an unknown quantity at this point
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
halifaxer is offline   Reply With Quote
Old 03-27-2009, 02:14 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-29-2009, 02:56 PM   PM User | #5
halifaxer
New Coder

 
Join Date: Feb 2008
Posts: 37
Thanks: 4
Thanked 0 Times in 0 Posts
halifaxer is an unknown quantity at this point
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...
halifaxer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 PM.


Advertisement
Log in to turn off these ads.