Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post

    Cool Nasty Problem (Solved!!!)

    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:
    http://localhost/index.php?category=$category&make=$model&go=go
    to this:
    http://localhost/$category_$model.hw

    I'm using this code as well:
    Code:
    	if($_REQUEST['category'])
    	{
    	$model = $_REQUEST['make'];
    	$category = $_REQUEST['category'];
    	$category = clean($category);
    	search($category, $model);	
    	}
    And Here's the search function:
    Code:
    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";
    	}
    	else
    	{
    		while ($rm = mysql_fetch_array($qm)){
    			extract($rm);
    			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...
    Last edited by M.W.S.; 08-04-2008 at 01:26 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    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" );

  • #3
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post
    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...

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post
    Thanks for replies. However, I did it using this method:

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •