954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Object not found! The requested URL was not found on this server.

Hi all

I have uncountered a problem which has me totally confused. The problem is I have created a website with a login form. Everything so far has been working fine. but then when I try to login all of a sudden I’m hit with a

"Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
29/08/2011 15:05:42
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
."

coming from my localhost. I don't think it has anything to do with the actual login script itself but more to do with the Apache config files/modules. Any suggestions would be much appreciated as this problem has me stumped

Thanks

codeblock
Light Poster
43 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

on your login form what you have set for ACTION ?

<form action=???>
sv3tli0
Junior Poster in Training
78 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
 

on your login form what you have set for ACTION ?

<form action=???>

Hi sv3tli0,

<form action="<?php echo <strong>pf_script_with_get($SCRIPT_NAME)</strong>; ?>" method="post">

if(!function_exists('<strong>pf_script_with_get</strong>')){	

function pf_script_with_get($script) {
	$page = $script;
	$page = $page . "?";

	foreach($_GET as $key => $val) {
		$page = $page . $key . "=" . $val . "&";
	}
  
	return substr($page, 0, strlen($page)-1);
}
}
codeblock
Light Poster
43 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

I think you have some big errors at your code.
First I don't understand how you use $_GET at your function.. ?

one normal login form should be as

<form action="login.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Login"></form>


At this case after submit you will POST this data in php format:
$_POST["username"]="THE_NAME_YOU_ENTER";
$_POST["password"]="THE_PASSWORD_YOU_ENTER";

You cant use login.php?username=XXX&password=XXX for ACTION.

sv3tli0
Junior Poster in Training
78 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
 

I think you have some big errors at your code. First I don't understand how you use $_GET at your function.. ?

one normal login form should be as

<form action="login.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Login"></form>

At this case after submit you will POST this data in php format: $_POST["username"]="THE_NAME_YOU_ENTER"; $_POST["password"]="THE_PASSWORD_YOU_ENTER";

You cant use login.php?username=XXX&password=XXX for ACTION.


This is the login page which should explain the whole process

<?php  
require("sessions.php");
require("config.php");
require("functions.php");

if(isset($_SESSION['USERNAME']) == TRUE){
	header("Location: " . $config_basedir . "userhome.php");
}

if(isset($_POST['submit'])) {

	$sql = "SELECT * FROM users,register WHERE users.id = register.user_id AND register.username = '" . $_POST['username'] . "' AND register.password = '" . $passwordcrypted . "';";
	
	$result = mysql_query($sql);
	$numrows = mysql_num_rows($result);
	
	session_register("USERNAME");
	session_register("USERID");
	
	if(isset($numrows) == 1) {	
		$row = mysql_fetch_assoc($result);
		
		if($row['active'] == 1) {
				
		$_SESSION['USERNAME'] = $row['username'];
		$_SESSION['USERID'] = $row['id'];	

        if(isset($_GET['ref'])){
          $ref = $_GET['ref'];
			switch($_GET['ref']) {

				case "newitem":
					header("Location: " . $config_basedir . "/newitem.php");
				break;
				           			
				case "viewregister":
					header("Location: " . $config_basedir . "/viewregister.php?id=" . $_GET['id']);
				break;
				
				case "userhome":
					header("Location: " . $config_basedir . "/userhome.php");
				break;
               				
				default:
					header("Location: " . $config_basedir);   
				break;
			}  
          }			
		}  
		else {
			require("header.php");
			echo "This account is not verified yet. You were emailed a link to verify the account. Please click on the link in the email to continue.";
		}			
	}
	else {
		header("Location: " . $config_basedir . "/login.php?error=1");
	}
}
else {

	require("header.php");

	echo "<hr><h1><label class='titleBlue'>Account Login</label></h1></hr>";
	echo "<hr></hr>";
    if(isset($_GET['error'])){
       $error = $_GET['error'];
		switch($_GET['error']){			
		 case "username":
		 echo "<strong><h4>Incorrect login, please enter correct username!</h4>";
		break; 
		 case "password1":
		 echo "<strong><h4>Incorrect login, please enter correct password!</h4></strong>";
		break; 
	  default:
		echo "<strong><h4>Incorrect username or password, please try again!</h4>";
		break;

	}
}	
	
?> 
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">

<table>
<tr><td colspan="2" bgcolor="#0000CD"> <label class="texts"><strong>Use a valid username and password to gain access to your userspace.</strong></label></td>
</tr>
<tr>
	<td>Username</td>
	<td><input type="text" STYLE="foreground:#ffffff; color:#eaeaea; id="username"name="username" value="bob" onfocus="clearMe(this)"/></td>
</tr>
<tr>
	<td>Password</td>
	<td><input type="password" id="password1"name="password1" value="passwordy"></td>
</tr>
<tr>
	<td></td>
	<td align = right><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>



</form>

<?php
}

require("footer.php");
?>
codeblock
Light Poster
43 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

This is the login page which should explain the whole process

<?php  
require("sessions.php");
require("config.php");
require("functions.php");

if(isset($_SESSION['USERNAME']) == TRUE){
	header("Location: " . $config_basedir . "userhome.php");
}

if(isset($_POST['submit'])) {

	$sql = "SELECT * FROM users,register WHERE users.id = register.user_id AND register.username = '" . $_POST['username'] . "' AND register.password = '" . $passwordcrypted . "';";
	
	$result = mysql_query($sql);
	$numrows = mysql_num_rows($result);
	
	session_register("USERNAME");
	session_register("USERID");
	
	if(isset($numrows) == 1) {	
		$row = mysql_fetch_assoc($result);
		
		if($row['active'] == 1) {
				
		$_SESSION['USERNAME'] = $row['username'];
		$_SESSION['USERID'] = $row['id'];	

        if(isset($_GET['ref'])){
          $ref = $_GET['ref'];
			switch($_GET['ref']) {

				case "newitem":
					header("Location: " . $config_basedir . "/newitem.php");
				break;
				           			
				case "viewregister":
					header("Location: " . $config_basedir . "/viewregister.php?id=" . $_GET['id']);
				break;
				
				case "userhome":
					header("Location: " . $config_basedir . "/userhome.php");
				break;
               				
				default:
					header("Location: " . $config_basedir);   
				break;
			}  
          }			
		}  
		else {
			require("header.php");
			echo "This account is not verified yet. You were emailed a link to verify the account. Please click on the link in the email to continue.";
		}			
	}
	else {
		header("Location: " . $config_basedir . "/login.php?error=1");
	}
}
else {

	require("header.php");

	echo "<hr><h1><label class='titleBlue'>Account Login</label></h1></hr>";
	echo "<hr></hr>";
    if(isset($_GET['error'])){
       $error = $_GET['error'];
		switch($_GET['error']){			
		 case "username":
		 echo "<strong><h4>Incorrect login, please enter correct username!</h4>";
		break; 
		 case "password1":
		 echo "<strong><h4>Incorrect login, please enter correct password!</h4></strong>";
		break; 
	  default:
		echo "<strong><h4>Incorrect username or password, please try again!</h4>";
		break;

	}
}	
	
?> 
<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">

<table>
<tr><td colspan="2" bgcolor="#0000CD"> <label class="texts"><strong>Use a valid username and password to gain access to your userspace.</strong></label></td>
</tr>
<tr>
	<td>Username</td>
	<td><input type="text" STYLE="foreground:#ffffff; color:#eaeaea; id="username"name="username" value="bob" onfocus="clearMe(this)"/></td>
</tr>
<tr>
	<td>Password</td>
	<td><input type="password" id="password1"name="password1" value="passwordy"></td>
</tr>
<tr>
	<td></td>
	<td align = right><input type="submit" name="submit" value="Login!"></td>
</tr>
</table>



</form>

<?php
}

require("footer.php");
?>

Taking a second look, i think it has more to do with my sessions. if i type the whole url i'll get the error message

"Notice: Undefined index: USERNAME in C:\xampp\htdocs\site\auction\userhome.php on line 14"

codeblock
Light Poster
43 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 
<?php

error_reporting(0);

?>


is the solution

Rhamises
Light Poster
31 posts since Aug 2011
Reputation Points: 23
Solved Threads: 5
 

I think that you have not just one problem .

<td><input type="text" STYLE="foreground:#ffffff; color:#eaeaea;" id="username"name="username" value="bob" onfocus="clearMe(this)"/></td>

First correct this line because you haven't close the style tag


Can you open your page in browser, click your right button of mouse open source code and check
Your problem is there because when you submit FORM your browser redirect you to the page written in the ACTION and there is your problem.

sv3tli0
Junior Poster in Training
78 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
 
<form action="<?php echo pf_script_with_get(<strong>$SCRIPT_NAME</strong>); ?>" method="post">

The bold text should be$_SERVER['SCRIPT_NAME'].

What is the purpose that the function pf_script_with_get doing ?

If you want the form action to the same page. Use $_SERVER['REQUEST_URI'] which returns the current url including query string (ie., you can get those with $_GET method ), or use $_SERVER['PHP_SELF'] which returns the current url without query string.

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

Try to replace your

<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">


with

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
sv3tli0
Junior Poster in Training
78 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
 

Try to replace your

<form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">

with

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">

Thanks for your help guys but i've found the problem and its solved

codeblock
Light Poster
43 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

Thanks for your help guys but i've found the problem and its solved

codeblock
Light Poster
43 posts since Feb 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: