1

hi I have a site where the links menu is read from a database and created in the format of index.php?page=mypage

how can I check that "mypage" is a page that exists in the database, so that users can't just add anything into the url?

thanks xx

2
  • Database? What database? If the data is read from the database, how can it NOT be in the database - unless your database is a very long way from being normalized. Commented Jan 18, 2011 at 12:31
  • I was concerned about the user putting their own value in the url that didn't exist. Commented Jan 22, 2011 at 20:08

2 Answers 2

1

If your pages are stored within the database: check the result set of the SQL-Query you´re sending to the database and don´t forget to escape characters to deny possible SQL-injection... ( mysql_real_escape_string() )

Sign up to request clarification or add additional context in comments.

Comments

1

Use a whitelist approach, something like this:

$allowedKeys = array('myPage', 'yourPage', '...Page');

$_GET = array_intersect_key($_GET, array_flip($allowedKeys));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.