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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

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

Post 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");
?>
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post 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.
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post 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");
?>
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post 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"); 
?>
Post Reply