i have a script Make pages like this http://mysite.com/page.php?id=45 and in the db just 50 pages and the problem is : if i called the page like http://mysite.com/page.php?id=654654646 it's open with any data .. so please help me to make reduction i need redirect the pages that i don't create in my db to home page and redirect this page "http://mysite.com/page.php" to home page too..
You need to put some kind of a check to see if the number (id) exists, so show us your current sql statement or to give you an idea here's some code: $id = $_GET['id']; $check = mysql_query("SELECT * FROM table WHERE id='$id';") or die(mysql_error()); if (mysql_num_rows($check) == 0) { // not found header("Location: http://mysite.com/page.php"); // go here } else { // current code here, which loads a page } PHP:
Yes, i do agree, just check for the id first, when it satisfy none zero results then you can continue to next process. Have a try
Try something like this : if(isset($_GET['id']) && strlen($_GET['id']) > 0) { $result = mysql_query("SELECT * FROM pages WHERE id = '".filter_var($_GET['id'],FILTER_SANITIZE_NUMBER_INT)."'"); if(mysql_num_rows($result) > 0) { //page exists } else { header("Location:http://mysite.com/page.php"); } } PHP: