Help using $_GET in PHP to locate page my visitor is on

Status
Not open for further replies.

Jeff-DBA

New member
Okay so I have a database of credit cards that I have built. I am displaying them in table format, dynamically, to the user depending on what page they are on (low-interest, rewards, high-interest etc.) I need to grab only certain cards from the database depending on what page the user is on. I am under the impression that I should be using the $_GET function to grab the user location from the header, I just can't figure it out. I was going to grab the page they are on, assign that a variable, and then pass that variable to my mysql_fetch_array(variablehere) so it knows what to spit out. Any help would be very much appreciated.

Thanks!

Jeff
 


First off $_GET is a variable, not a function. To understand how GET and POST are used you can read part 2 of my noobie guide to scraping:
Noobies Guide on How to Scrape: Part 2 - URLs, URL Variables, and using Live HTTP Headers | MadPPC

Using GET variables are probably the easiest way to go IMHO, but honestly if your that clueless it'd take forever to explain throughly.

Roughly this is what your looking at:

Have one main page that basically acts like a template. Depending on what you want to show the user you have to pass in a GET variable for example, lets say that our template page is just our index.php page, and in one example we want to see high cash rewards, and for another example we want to see low interest. You issue links that look like:


Then you'd use PHP on the page to pull the value of cards and display the relevant info:

Code:
if($_GET[cards] == 'highcashrewards'){
//make the query for high cash reward cards
}
elseif($_GET[cards] == 'lowinterest'){
//do a query for low interest cards
}
//etc.......

Get it?
 
I guess I don't get what you're saying because it sounds like you're trying to make something that's simple into something complicated.

Why not make a page, "low-interest.php" for example, and display it to the user? What event is connected with what type of page to show the user?
 
That's the exact reason, it's simple yet complicated. You could just create separate files, but that's both a waste of your time and space.

Your basic argument is "why not create a static html file"? Reason being is PHP can be a dynamic language. Once you realize that your golden.
 
You need to realize it's not as simple as you thought and start studying PHP extensively. You'll find your answer.
 
Something nice to have is 'pretty URLs'. So using Rage9's code, instead of having the browser display your URL as "domain.com/index.php?cards=lowinterest" you can make them display as domain.com/lowinterest/ or something else a bit nicer like this:

1. Create a file called .htaccess
2. Include this code inside:

Code:
[FONT=monospace]RewriteEngine On
RewriteBase /
RewriteRule ^([^/\.]+)/ index.php?cards=$1 [L][/FONT]

3. Upload to same folder as index.php.
4. domain.com/lowinterest/ should load the contents of domain.com/index.php?cards=lowinterest
 
You need to realize it's not as simple as you thought and start studying PHP extensively. You'll find your answer.

My post was in response to the original post. Trying to figure out what page a user is on would be needlessly complicated.

It is simple.
 
Ok, this should work on most servers:
Code:
<?
function thispage(){
return basename(__FILE__);
}
?>

It should return the name of the page your user is on (low-interest.php in your example). Not tested it though.

And since you're asking us to code it for you, I would not stay in such an arrogant position.
 
And since you're asking us to code it for you, I would not stay in such an arrogant position.

I'm not asking you to code anything for me so I'll stay in the arrogant position. Maybe you should get in the bend over position as you re-read the post.
 
Status
Not open for further replies.