Php (Meta Refresh) Redirection Problem !!

Discussion in 'PHP' started by nita, May 5, 2007.

  1. #1
    Hi
    I'm building little script (movie collection).

    The problem is that when:
    -there is no results - browser is showing a communicate and redirecting back to the root (index.php) after 2 sec
    -input is less then 2 char - browser is showing a communicate and redirecting back to the root (index.php) after 2 sec

    to test it go to:
    http://www.nita-on-line.com/movies/

    code for search part of the application --

    
    else if(isset($_POST['submit'])||isset($_POST['search'])) // when search button is pressed
    {
    echo "
    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
    'http://www.w3.org/TR/html4/loose.dtd'>
    <html>
    <head>
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    <LINK REL='StyleSheet' href='movies.css' TYPE='text/css'>
    <title>Nita Movies</title>
    </head>
    <body>
    <table width='950'>
    <tr>
    	<td bgcolor='#663300' width='180' border='0' cellspacing='0' cellpadding='0'  valign='top' class='font2' >";
    	$result = mysql_query("SELECT * FROM category ORDER BY cat") or die(mysql_error());
    	while($row = mysql_fetch_array( $result )) 
    	{
    	
    	echo "<A href='index.php?cat=$row[cat]'>$row[cat]</a><br>";
    	}
    	echo "	
    	<br>
    	<form method='post' action='$php_self'>
    	<input type='text' name='search' size=25 maxlength=25 minleneght=2><br>
    	<input type='Submit' name='Submit' value='Submit'>
    	</form>
    	</td>
    	
    	<td class='font2'>";
    
    	$PHP_SELF = $_SERVER['PHP_SELF'];
    
    	$search=$_POST["search"];
    
    	$minchar = 2;
    	if (strlen($search) < $minchar)
    	{
    	    echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
    				'http://www.w3.org/TR/html4/loose.dtd'>
    				<html>
    				<head>
    				<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    				<META HTTP-EQUIV='REFRESH' CONTENT='2; URL=$PHP_SELF'>
    				<LINK REL='StyleSheet' href='movies.css' TYPE='text/css'>
    				<title>Nita Movies</title>
    				</head>
    				<body>";
    
    		echo "Search must be longer than 2 characters.
    		</body>
    		</html>
    ";
    } 
    	else 
    	{
    	    $result = mysql_query("SELECT * FROM movies WHERE name LIKE '%$search%' 
    	    OR cast LIKE '%$search%' OR director LIKE '%$search%' 
    	    OR year LIKE '%$search%' OR production LIKE '%$search%'
    	    OR genere LIKE '%$search%' OR language LIKE '%$search%'");
    	
    	    $numrows=mysql_num_rows($result);
    	    if ($numrows == 0)
      	    {
      	          echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
    				'http://www.w3.org/TR/html4/loose.dtd'>
    				<html>
    				<head>
    				<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    				<META HTTP-EQUIV='REFRESH' CONTENT='2; URL=$PHP_SELF'>
    				<LINK REL='StyleSheet' href='movies.css' TYPE='text/css'>
    				<title>Nita Movies</title>
    				</head>
    				<body>";
    			echo "<p>Sorry, your search returned 0 results</p>
    			</body>
    			</html>
    ";
    			
      	    }
    	    else 
    	    { 
    	        while($row=mysql_fetch_array($result))
    	        {	
           	        include "display_rec.php";
    	        }
    	    }
    	}
     	echo "
    	</td>
    </tr>
    </table>
    </body>
    </html>
    ";
    
    }
    
    Code (markup):
    For example when i.m browsing one of the categories and then do search resulting in these communicates. saerch for "a" or "hghjdjjd"
    Browser is redirecting me to the root of the application, what i want to be done, is that browser will redirect me to the place i started my search from.

    if some one can help me to find a solution for that one.
    im happy to publish entire code of the apllication (its not too long) if you think that my help to solve a problem.

    Thanks a lot in advance
    Nita
     
    nita, May 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try replacing:
    
    $PHP_SELF = $_SERVER['PHP_SELF'];
    
    PHP:
    With:
    
    $PHP_SELF = $_SERVER['REQUEST_URI'];
    
    PHP:
     
    nico_swd, May 5, 2007 IP
  3. nita

    nita Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    thx for advice

    but i'm afraid this option is not working too.

    anyone - some idea?

    nita
     
    nita, May 5, 2007 IP
  4. Neoto

    Neoto Active Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #4
    Try this:
    
    $PHP_SELF = $_SERVER['HTTP_REFERER'];
    PHP:
    $_SERVER['HTTP_REFERER'] should point to the page where the search was made.
     
    Neoto, May 5, 2007 IP
  5. nita

    nita Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Thanks big time Neoto.

    i have been sitting on this one for 2 days,
    posted to some other forums, too - no solution - i almost gave it up,
    all done thanks to You

    Nita
     
    nita, May 5, 2007 IP
  6. Neoto

    Neoto Active Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #6
    No problem :)
     
    Neoto, May 5, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Note that HTTP_REFERER is sent by the browser, and not all browsers send it. So I'd rather do it this way:
    
    $PHP_SELF = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF'];
    
    PHP:
     
    nico_swd, May 5, 2007 IP