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".