Jump to content

Redirect issue


dhimok

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/56948-redirect-issue/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56948-redirect-issue/#findComment-281346
Share on other sites

>

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.

 

Link to comment
https://forums.phpfreaks.com/topic/56948-redirect-issue/#findComment-281441
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/56948-redirect-issue/#findComment-281452
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.