I'm new to php, so I follow a tutorial from WellBro. I'm making a registration and login. But There's a mistake in my code and it always gives the wrong titels. After log in, I need to see "home, profiel and Log Out" but I keep seeing "home, log in and registreer". So I think there's a mistake with my loggedin(). Can someone please help me? :)
part of login
<?php
if (loggedin()) {
?>
<a href='index.php'>Home</a>
<a href='profile.php'>Profiel</a>
<a href='logout.php'>Log Out</a>
<?php
}else{
?>
<a href='index.php'>Home</a>
<a href='login.php'>Log in</a>
<a href='register.php'>Registreer</a>
<?php
}
>
<?php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
if(empty($username) or empty ($password)){
echo"<p>Gelieve al de velden in te vullen.</p>";
}else{
$check_login = mysql_query("SELECT id, type FROM users WHERE username='$username' AND password = '$password'");
if (mysql_num_rows($check_login)==1){
$run = mysql_fetch_array($check_login);
$user_id=$run['id'];
$type = $run ['type'];
if($type == 'd'){
echo "<p>Je account is nog niet geactiveerd. Je ontvangt een mail zodra dit in orde is. Als je na lange tijd nog steeds niet kunt inloggen, neem dan contact op met één van de trainers.</p>";
}else{
$_SESSION['user_id'] = $user_id;
echo "<script> window.location.replace('membersonly.php') </script>";
}
}else{
echo "<p>Ongeldige gebruikersnaam of wachtwoord.</p>";
}
}
}
?>
function.php
<?php
session_start();
function loggedin() {
if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
return true;
}else{
return false;
}
}
?>
part of membersonly.php
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php
if (loggedin()) {
?>
<a href='index.php'>Home</a>
<a href='profile.php'>Profiel</a>
<a href='logout.php'>Log Out</a>
<?php
}else{
?>
<a href='index.php'>Home</a>
<a href='login.php'>Log in</a>
<a href='register.php'>Registreer</a>
<?php
}
?>