- session_start: documentation ( source)
- printf: documentation ( source)
<?php
session_start();
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$city = "Amersfoort";
/* create a prepared statement */
if ($stmt = $mysqli->prepare("SELECT * FROM `users` WHERE username=? AND password=?")) {
/* bind parameters for markers */
$stmt->bind_param("ss", $username,$password);
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($result);
/* fetch value */
$stmt->fetch();
if( count($result) > 0 ){
$_SESSION['authentificated'] = true;
$_SESSION['username'] = $username;
}
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>