Hi all,
I have been following some tutorials and I now have a working log in and register system.
What I then tried to do was include the php files onto my index page.
When I try to do so, I get the following - I have tried googling but my lack of knowledge is holding me back from deciphering what more experienced people are saying in relation to this.
The warnings are:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Users/adamhewitt/Sites/demo/index.php:13) in /Users/adamhewitt/Sites/demo/register.php on line 8
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/adamhewitt/Sites/demo/index.php:13) in /Users/adamhewitt/Sites/demo/register.php on line 8
Notice: Constant MYSQL_USER already defined in /Users/adamhewitt/Sites/demo/connect.php on line 13
Notice: Constant MYSQL_PASSWORD already defined in /Users/adamhewitt/Sites/demo/connect.php on line 16
Notice: Constant MYSQL_HOST already defined in /Users/adamhewitt/Sites/demo/connect.php on line 19
Notice: Constant MYSQL_DATABASE already defined in /Users/adamhewitt/Sites/demo/connect.php on line 22
I understand what they mean but I don’t know how to correct what I have done.
The system works fine with them but I am the sort of person that doesn’t like errors.
<?php
//index.php
?>
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<?php require 'login.php' ?>
<?php require 'register.php' ?>
</body>
</html>
<?php
//register.php
session_start();
require 'lib/password.php';
require 'connect.php';
if(isset($_POST['register'])){
$username = !empty($_POST['username']) ? trim($_POST['username']) : null;
$pass = !empty($_POST['password']) ? trim($_POST['password']) : null;
$sql = "SELECT COUNT(username) AS num FROM users WHERE username = :username";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':username', $username);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row['num'] > 0){
die('That username already exists!');
}
$passwordHash = password_hash($pass, PASSWORD_BCRYPT, array("cost" => 12));
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':username', $username);
$stmt->bindValue(':password', $passwordHash);
$result = $stmt->execute();
if($result){
echo 'Thank you for registering with our website.';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<h1>Register</h1>
<form action="register.php" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username"><br>
<label for="password">Password</label>
<input type="text" id="password" name="password"><br>
<input type="submit" name="register" value="Register"></button>
</form>
</body>
</html>
any help on this would be appreciated.
I am very very new to this so please try and explain things as if you are talking to an actual idiot.
Thanks
Adam