Files from the Register & Login Tutorials not showing

Post here is you are having problems with any of the tutorials.
Post Reply
michaelnwani
Posts: 2
Joined: Sat Jan 07, 2012 7:44 am

Files from the Register & Login Tutorials not showing

Post 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".
Last edited by jacek on Sun Jan 08, 2012 12:43 am, edited 1 time in total.
Reason: code tags...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Files from the Register & Login Tutorials not showing

Post 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');
?
Image
michaelnwani
Posts: 2
Joined: Sat Jan 07, 2012 7:44 am

Re: Files from the Register & Login Tutorials not showing

Post 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).
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Files from the Register & Login Tutorials not showing

Post 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.
Image
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: Files from the Register & Login Tutorials not showing

Post by bowersbros »

Check permissions also. If it isnt allowed to be read by everybody, maybe it wont be recognized either?
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Post Reply