Comparing $_Get Variable to an array? - Advice needed too...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xpiamchris
Forum Newbie
Posts: 10
Joined: Thu Jan 15, 2009 4:17 pm

Comparing $_Get Variable to an array? - Advice needed too...

Post by xpiamchris »

Scenario:
A user logs in and has a list of "albums" he can choose from. Once the user clicks on a link to the album, it sends a $_GET # to an editalbum.php page which pulls up the appropriate album page.

To ensure that the user does not go to a page that is not his own, I need to compare the $_GET variable with a query from mysql that shows which albumids belong to that user.

E.g.
User 1 has album ids, 1, 3, 5.
User 2 has album ids 2, 4.

So if User 1 tries to go to the page with $_GET variable equal to 3, he can access the page as it is compared to the values 1,3,5. However, if he tries to get in with $_GET variable equal to 4, he is redirected to a "cannot access" page.

How would you go about doing this?

Thank you in advance.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Comparing $_Get Variable to an array? - Advice needed too...

Post by Apollo »

Exactly what is the difficulty? Do you know how to extract (with SQL) the list of albums for the particular user?

Or are you looking for the in_array function?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Comparing $_Get Variable to an array? - Advice needed too...

Post by requinix »

And to throw in another idea, it is possible to have multiple conditions in a SQL query. Like a condition that the user ID is X AND the album number is Y.
Post Reply