Page 1 of 1

Files from the Register & Login Tutorials not showing

Posted: Sat Jan 07, 2012 7:49 am
by michaelnwani
Hi there, my first post. I was following the register and login tutorials and for some reason none of them will display, for example when I click on my login.php file, I just get a white screen. Here's my code for example:
Login.php
<?php
include('init.inc.php');

$errors = array();

if (isset($_POST['username'], $_POST['password'])){
	if (empty($_POST['username'])){
		$errors[] = 'Please enter your username.';
	}
	if (empty($_POST['password'])){
		$errors[] = 'Please enter your password.';
	}
	
if (valid_credentials($_POST['username'], $_POST['password']) == false){
		$errors[] = 'Your username or password is incorrect';
	
	}

	if (empty($errors)){
		$_SESSION['username'] = htmlentities($_POST['username']);
		//if correct, they get sent to protected.php
		header('Location: protected.php');
		die();
	}	

}

?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
<title>Login Page</title>
</head>
	<body>
		<div>
		<?php
		if (empty($errors) === false){
			?>
			<ul>
				<?php
				foreach($errors as $error){
					echo "<li>{$error}</li>";
				}
				?>
			</ul>
			<?php
		
		}else{
		echo 'Need an account? <a href="register.php">Register here</a>';}
		?>
		</div>
		<form action="" method="post">
		<p>
			<label for="username">Username:</label>
			<input type="text" name="username" id="username" value ="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>"/>
		</p>
		<p>
			<label for="password">Password:</label>
			<input type="password" name="password" id="password" />
		</p>
		<p>
			<input type="submit" value="Login" />
		</p>
		</form>
	</body>
</html>
Now as far as the style.css stylesheet goes, I made one, but there's nothing in it, it's blank. But I don't think that has any place in stopping this stuff from showing.

As for my init.inc.php, the code is:
<?php

session_start();

$exceptions = array('register','login');
//extracting "register"
$page = substr(end(explode('/',$_SERVER['SCRIPT_NAME'])), 0, -4);

/*if the user is not in a page that is in the exceptions list, we check if they're
logged in, and if they aren't, they get sent to the login page*/

if (in_array($page, $exceptions)) === false){
	if (isset($_SESSION['username'] === false){
		header('Location: login.php');
		die();
	}
}

mysql_connect('localhost','root','root');
mysql_select_db('user_system');

$path = dirname(__FILE__); //always the full path to the file

include("{$path}/user.inc.php");


?>

I have every file (register.php,user.inc.php,protected.php, etc.) in the same folder just to practice with them, and their in the htdocs folder of my MAMP folder.

Again, I'm just getting a blank white screen on everything, no errors.

Please get back to me

Edit: Sorry that I don't know how to post the code in "code" format on the website, if someone would tell me how to I would. but running this in Coda, I see the error "Warning: include(init.inc.php): failed to open stream: No such file or directory in - on line 2 Warning: include(): Failed opening 'init.inc.php' for inclusion (include_path='.:') in - on line 2"

All my files are in the same area, and I don't understand what it means to "fail to open stream".

Re: Files from the Register & Login Tutorials not showing

Posted: Sun Jan 08, 2012 12:47 am
by jacek
michaelnwani wrote:I see the error "Warning: include(init.inc.php): failed to open stream: No such file or directory in - on line 2 Warning: include(): Failed opening 'init.inc.php' for inclusion (include_path='.:') in - on line 2"

All my files are in the same area, and I don't understand what it means to "fail to open stream".
"failed to open stream" simply means that the file was not able to be opened for some reason, if then tells you the reason "No such file or directory". Which means the file you tried to include does not exist, in the videos I put the init.inc.php file in a folder called "core" so maybe it should have been
include('core/init.inc.php');
?

Re: Files from the Register & Login Tutorials not showing

Posted: Sun Jan 08, 2012 4:27 am
by michaelnwani
Indeed, but I kept them all right in the same folder just for basic testing. No clue why it would not register :/ unless this init.inc.php file has to be in a different folder from the rest of the content (until your tutorial I hadn't heard of an init.inc.php file, I've only been web coding for like a month).

Re: Files from the Register & Login Tutorials not showing

Posted: Mon Jan 09, 2012 9:45 pm
by jacek
Well there is no other possibel cause, if the file is in the same folder then all I can suggest is that you make suire the file name is correct.

Re: Files from the Register & Login Tutorials not showing

Posted: Mon Jan 09, 2012 11:35 pm
by bowersbros
Check permissions also. If it isnt allowed to be read by everybody, maybe it wont be recognized either?