TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-04-2008, 09:42 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default $_get

Hi!

My question is a fairly simple question, but when I thought about it, I really had no clue..

So basicly.
I have a member.php script.

If I write member.php?u=4, it would generate and echo out a member profile of the user with user_id = 4.

However, if I write member.php?g=admins, it would generate and echo out a list of all the members that are currently in the group "admins"(with the field rank, set to 3).

And if I write member.php?show=all, it would generate a list of all the members.

So my question is as following.

How do I prevent users from writing member.php?u=4&show=all&g=mods ????

How can I force them just to have one, and if they write all of them, show some kind of error message, or perhaps redirect to the list of all as a default "member.php" -page ??

PHP Code:
if(count($_GET) > 1) {
echo 
'Na na na!';
}

else {
$group $_GET['g'];
$user $_GET['u'];
$default $_GET['show'];
}
// etc.. 
Possible? Wrong method? Better method?

Thanks in advance!
__________________
Tanax is offline  
Reply With Quote
Old 02-05-2008, 12:15 AM   #2 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Try:
PHP Code:
if (count($_GET) > 1) { /* error */ 
$_GET is an array, so you have to use count() to count how many parts to the array there are.
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 02-05-2008, 01:09 AM   #3 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

It's simple: just get the one you're interested the most in. If the user id is more important than the group, then take only the user id and ignore the rest. Or, you could go for showing the user an error, or perhaps even redirecting them somewhere. As long as the request is not done via the website urls, you can do what ever you want with the unwanted requests.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
Tanax (02-05-2008)
Old 02-05-2008, 10:02 AM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Andrew View Post
Try:
PHP Code:
if (count($_GET) > 1) { /* error */ 
$_GET is an array, so you have to use count() to count how many parts to the array there are.
Yea that's what I thought, thanks

Quote:
Originally Posted by xenon View Post
It's simple: just get the one you're interested the most in. If the user id is more important than the group, then take only the user id and ignore the rest. Or, you could go for showing the user an error, or perhaps even redirecting them somewhere. As long as the request is not done via the website urls, you can do what ever you want with the unwanted requests.
Huh? Code example?
__________________
Tanax is offline  
Reply With Quote
Old 02-05-2008, 02:25 PM   #5 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

Quote:
How do I prevent users from writing member.php?u=4&show=all&g=mods ????

How can I force them just to have one, and if they write all of them, show some kind of error message, or perhaps redirect to the list of all as a default "member.php" -page ??
What you are looking at is the logic of page design. You have to determine in what order of importance the variables will be. For instance, I'd rank the specific user link and a group link as more important than a tag that tells me to show everyone. Then it's sorting those out into the logic sections.

It's as simple as an if-then-else block, in series to construct the path of logic we decided upon above.

PHP Code:
if(count($_GET) > 0) {
  if(isset(
$_GET['u'])) {
    
// Show your member specific page
  
} elseif(isset($_GET['g'])) {
    
// Show your group specific listing
  
} elseif(isset($_GET['show'])) {
    
// Show all members or whatever page of the list you want.
  
} else {
    
// Handle the invalid input as you wish...
  
}
} else {
  
// No input, so show your default page.

__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
The Following User Says Thank You to RobertK For This Useful Post:
Tanax (02-05-2008)
Old 02-05-2008, 04:08 PM   #6 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Thank you I solved it
__________________
Tanax is offline  
Reply With Quote
Old 02-05-2008, 04:09 PM   #7 (permalink)
The Addict
Top Contributor Good Samaritan 
 
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
RobertK is on a distinguished road
Default

You're welcome, glad to help you out.
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
RobertK is offline  
Reply With Quote
Old 02-06-2008, 08:25 AM   #8 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

instead of using isset, use !empty() which verify if the var exists and if is not null. The problem when you use isset is that if a user go to this page: index.php?u= the condition if(isset($_GET["u"])) is validated.
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
The Following User Says Thank You to Gibou For This Useful Post:
Tanax (02-06-2008)
Old 02-06-2008, 10:11 AM   #9 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Gibou View Post
instead of using isset, use !empty() which verify if the var exists and if is not null. The problem when you use isset is that if a user go to this page: index.php?u= the condition if(isset($_GET["u"])) is validated.
Thanks!

But I run a check on the userid, and if it's not found.. then it gives a msg "A user with that ID does not exist", so I solved it anyways... :P
__________________
Tanax is offline  
Reply With Quote
Old 02-06-2008, 10:46 AM   #10 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

Yes, of course but it's more friendly to display a default page if the $_GET["u"] is empty (like the home page) instead of an error message. Keep your error message in case of the user id passed in the GET var is wrong (ex: $_GET["u"]=toto).

Whatever, it's a detail, do what you want :)
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 02-06-2008, 02:34 PM   #11 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

I was just about to suggest a similar method as RobertK just posted, damn your too fast Robert =P
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:08 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design