dhimok Posted June 24, 2007 Share Posted June 24, 2007 Hi! I have this script where I want to redirect if no entries found before the rest of the script is executed. $sql = dbQuery("SELECT * FROM tbl WHERE id = '".$_GET["id"]."'"); if(mysql_num_rows($sql) == 0) { // do redirect to another page } // the code above is included on top of page and the one below in body // here s the other code that gets the record ID from querystring $sql = dbQuery("SELECT * FROM tbl WHERE id = '".$_GET["id"]."'"); // the rest As known I get the: Warning: Cannot modify header information - headers already sent by and no redirection Thanks Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 24, 2007 Share Posted June 24, 2007 Did you read the sticky? Quote Link to comment Share on other sites More sharing options...
.Stealth Posted June 24, 2007 Share Posted June 24, 2007 heres a link: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html as it says, no output in the headers at all including whitespace. Quote Link to comment Share on other sites More sharing options...
dhimok Posted June 24, 2007 Author Share Posted June 24, 2007 Ok, I cleared the white space and I dont get the error message, but I get this other message now Problem loading page The page isn't redirecting properly Quote Link to comment Share on other sites More sharing options...
.Stealth Posted June 24, 2007 Share Posted June 24, 2007 Maybe show us what your doing. Quote Link to comment Share on other sites More sharing options...
dhimok Posted June 24, 2007 Author Share Posted June 24, 2007 What I am trying to do is to redirect visitors if they try to misuse querystrings www.mysite.com/?id=400 If id matches the database record then show the info about that id If id doesnt exist in the database then redirect Thats what I will try to accomplish. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 24, 2007 Share Posted June 24, 2007 I think he meant show us the code which is failing. Quote Link to comment Share on other sites More sharing options...
dhimok Posted June 24, 2007 Author Share Posted June 24, 2007 Here s the code <?php // == required files == require_once("config/config.inc.php"); require_once("config/opendb.php"); // redirect $sqlRedir = dbQuery("SELECT * FROM table WHERE id = '" . $_GET["id"] . "'") or die(mysql_error()); if(mysql_num_rows($sqlRedir) == 0) { header("location: ". ROOT_DIR. "/"); } function getItem($id) { $retval = ''; if (isset($_GET["item"])) { $result = dbQuery("SELECT * FROM table WHERE id = '".$id."'"); $p = dbFetchObject($result, MYSQL_BOTH); ob_start(); include('includes/item.php'); $retval .= ob_get_contents(); ob_end_clean(); } return $retval; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Website name</title> </head> <body> <?=getItem($_GET["id"])?> </body> </html> I get Problem loading page and this . Using firefox Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Quote Link to comment Share on other sites More sharing options...
dhimok Posted June 24, 2007 Author Share Posted June 24, 2007 > Here s the code <?php // == required files == require_once("config/config.inc.php"); require_once("config/opendb.php"); // redirect $sqlRedir = dbQuery("SELECT * FROM table WHERE id = '" . $_GET["id"] . "'") or die(mysql_error()); if(mysql_num_rows($sqlRedir) == 0) { header("location: ". ROOT_DIR. "/"); } function getItem($id) { $retval = ''; if (isset($_GET["item"])) { $result = dbQuery("SELECT * FROM table WHERE id = '".$id."'"); $p = dbFetchObject($result, MYSQL_BOTH); ob_start(); include('includes/item.php'); $retval .= ob_get_contents(); ob_end_clean(); } return $retval; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Website name</title> </head> <body> <?=getItem($_GET["id"])?> </body> </html> I get Problem loading page and this . Using firefox Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Quote Link to comment Share on other sites More sharing options...
bigbob Posted June 24, 2007 Share Posted June 24, 2007 that means u are redirecting to a page that redirects back the main which redirects back the redirect page which redirects back to the main.... and so on. I find it helps to draw it out. Index.php -redirects- Redirect.php Redirect.php -redirects- Index.php <----There is your problem. You are redirecting between the same 2 pages forever in a circle. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.