Page 1 of 1

Im confused. Why am I unable to execute this code?

Posted: Tue May 27, 2003 9:35 am
by hairyjim
I have the following code, which if I try and execute without any <html></html> tags comes back with a 404 error from IIS.

Could anyone point me in the reason why? I'm really confused by this.

Code: Select all

<?php
  require('config.inc.php');
  require('sql.inc.php');

  $query = "SELECT id,user,name,pass=PASSWORD('".$_POST["pass"]."') FROM users WHERE user='".$_POST["login"]."' AND pass!=''";
  $result = @mysql_query($query, $sql);
  if( mysql_num_rows($result) != 1 ) {
    header("Location: /main.php?&err=true"); exit;
  }
		      
  $row = @mysql_fetch_array($result);
  if( $row[3] == 0 ) {
    header("Location: /main.php?err=pass"); exit;
  }
  
  $user_is_logged_in = true;
  $user_id = $row["id"];
  $user_login = $row["user"];
  $user_name = $row["name"];
				      
  require('session.inc.php');
  session_register("user_id");
  session_register("user_login");
  session_register("user_name");
  session_register("user_is_logged_in");
					        
  if(!isset($_GET["uri"]) || $_GET["uri"] == "")
     $uri = "/list.php";
  else
     $uri = $_GET["uri"];

  header("Location: $uri");
?>

Posted: Tue May 27, 2003 9:37 am
by []InTeR[]
Try to 'debug' the script by echo'ing each url first before redirecting.

Its just redirecting to a url that's not found.

Posted: Tue May 27, 2003 10:23 am
by hairyjim
Ahhhh - I have figured why I was getting no redirection.

This is from the Manual, which perhaps I should have read before using the function :oops:
The Header() function is used at the top of an HTML file to send raw HTTP header strings. See the HTTP 1.1 Specification for more information on raw http headers. Note: Remember that the Header() function must be called before any actual output is sent either by normal HTML tags or from PHP. It is a very common error to read code with include() or with auto_prepend and have spaces or empty lines in this code that force output before header() is called.
I had a few empty lines in the code which forced an output.

Ahhh well, now all I need to figure out is why this section of code is not working:

Code: Select all

<?php
if(!isset($_GET["uri"]) || $_GET["uri"] == "")
     $uri = "/list.php";
  else
     $uri = $_GET["uri"];
  header("Location:$uri");
?>

Posted: Tue May 27, 2003 10:32 am
by Zoram
try using a complete address such as :

Code: Select all

<?php 
if(!isset($_GET&#1111;"uri"]) || $_GET&#1111;"uri"] == "") 
     $uri = "/list.php"; 
  else 
     $uri = $_GET&#1111;"uri"]; 
  header("Location: http://" . $_SERVER&#1111;'HTTP_HOST'] . $uri"); 
?>