![]() |
$_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:
Thanks in advance! |
Try:
PHP Code:
|
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.
|
Quote:
Quote:
|
Quote:
It's as simple as an if-then-else block, in series to construct the path of logic we decided upon above. PHP Code:
|
Thank you :-D I solved it :-)
|
You're welcome, glad to help you out. :-)
|
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.
|
Quote:
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 |
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 :) |
I was just about to suggest a similar method as RobertK just posted, damn your too fast Robert =P
|
| All times are GMT. The time now is 12:34 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0