View Full Version : Nasty Problem (Solved!!!)

08-03-2008, 03:16 PM
I think I'm going to become mad soon.
I am building a search form ($_GET) with mod_rewrite for SEO friendly urls.
And because there are forms, I'm using header(location:...) to redirect
this page:
to this:

I'm using this code as well:

$model = $_REQUEST['make'];
$category = $_REQUEST['category'];
$category = clean($category);
search($category, $model);

And Here's the search function:

function search($a, $b){
header("Location: http://localhost/$a" . "_$b.hw" );
$qm = "SELECT * FROM car WHERE make = '$a' AND model = '$b'";
$qm = mysql_query($qm) or die(mysql_error());
if (mysql_num_rows($qm) == "0"){
echo "Not found";
while ($rm = mysql_fetch_array($qm)){
echo "Found!";

And the problem:

When I pass a variable using $_GET or $_REQUEST, I get this page:

Redirect Loop
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete.
* Have you disabled or blocked cookies required by this site?
* NOTE: If accepting the site's cookies does not resolve the problem, it is likely a server configuration issue and not your computer.

What to do? I've been trying to fix this for 2 days... :confused:

08-03-2008, 03:32 PM
Somebody else may be better able to help, but I'm not sure if this is correct:

header("Location: http://localhost/$a" . "_$b.hw" );

I think it should be.

header("Location: http://localhost/{$a}_{$b}.hw" );

08-03-2008, 03:37 PM
No progress :(

But I think that, the problem should be near that. Because, when I comment that line, I can access http://localhost/$category_$model.hw page without problem...

08-03-2008, 10:02 PM
Sending a redirect header will normally cause the following code to never execute. As soon as you send you're header("Location... you can no longer perform you're query.
This is going to be a pain no matter what you do. If you need to redirect, you'll need to move the header to the end of the function call. But you'll still need to do something with the extracted variables if I'm not mistaken they are imported into the current scope of the symbols table - they will be locked into the search function and destroyed when the function terminates. I may be wrong though, I've never used extract.
As for you're header, either of the above should work.

Redirect loops are caused by a page that sends a header to itself or another page which sends it back to the original calling page. You'll need to determine if a redirection is necessary based on where their current location is (I just debugged a script that had this exact problem).

08-04-2008, 01:25 PM
Thanks for replies. However, I did it using this method:

http://www.webmasterworld.com/forum92/6079.htm :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum