Jump to content

Problem With Code


natasha23

Recommended Posts

i am trying to create a secure login page and everytime i run the script i get an error saying that the server is redirecting the request in a way that will never complete.this is my code below if anyone can tell me what im doing wrong it would much much appreciated

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>  <title>login form</title></head><body><?php   require_once("nocache.php");  $id = $_POST["id"];  $pword = $_POST["pword"];  if (empty($id) || empty($pword)){	header("location: login.php");}  else { 	 require_once("conn.php");	 $sql = "select staffID, accessLevel from staff where staffID = '$id' and password = '$pword'";	 $rs = mysql_query($sql, $conn);	 if (mysql_num_rows($rs)> 0 ) {		 session_start();		 $_SESSION["who"] = $id;		 $_SESSION["level"] = mysql_result($rs,0,"accessLevel");		 header("location: selectView.php");		}	 else {	   header("location: login.php");}  }?><form id="f1" method="post" action="login.php"><p>Staff ID: <input type="text" name="id" value="V12345"/><br/>Password: <input type="password" name="pword" value="letmein" /><br/><input type="submit" value="log in" /> <input type="reset" /></p></form></body></html>

thanks in advance

Link to comment
Share on other sites

I am guessing that the name of your page is login.php

header("location: login.php");

That header is sent whenever this condition is true:

  $id = $_POST["id"];  $pword = $_POST["pword"];  if (empty($id) || empty($pword)){

That condition is always true except after receiving data from a form, so it keeps on redirecting.

Link to comment
Share on other sites

I am guessing that the name of your page is login.php
header("location: login.php");

That header is sent whenever this condition is true:

  $id = $_POST["id"];  $pword = $_POST["pword"];  if (empty($id) || empty($pword)){

That condition is always true except after receiving data from a form, so it keeps on redirecting.

so how can i fix this problem???ive been trying so many things and nothing seems to be working i just keep getting the same error
Link to comment
Share on other sites

You need a different way to detect if the form was submitted, checking if the ID or password is empty isn't enough. You should check if one of the $_POST variables is set. If it's set, regardless of whether or not it's empty, then the form was submitted and you can do your validation. If it's not set then the form wasn't submitted.

Link to comment
Share on other sites

You need a different way to detect if the form was submitted, checking if the ID or password is empty isn't enough. You should check if one of the $_POST variables is set. If it's set, regardless of whether or not it's empty, then the form was submitted and you can do your validation. If it's not set then the form wasn't submitted.
thank you i tried the isset function and that fixed the problem
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...