nanya bikin menu/login gan ??

Pertanyaan :

  1. Cara buat Login Session gimana ?
  2. Login berdasarkan User dan Admin ?
  3. unset() Session nya ?
<?php
require_once('config.php');
/*
include kl ngak butuh amat
*/
error_reporting(0);
?>
 
<!DOCTYPE html>
<html>
<head>
<!-- budayakan naro css ato media dalam folder media/asset.. biar rapi gitu -->
<link rel="stylesheet" type="text/css" href="style.css" />

/*
awali dengan load jquery
*/
    $(function() {
    $('.float a[href~="' + location.href + '"]').parents('li').addClass('active');
});

</head>
<body>
       
    <div id="container">
        <div id="menu">
            <ul class="float" id="simple">
            <li><a href="index.php">Home</a></li>
            <?php 
            $sql = mysqli_query("SELECT * FROM user", $connect);
            $data = mysqli_fetch_array($sql);
            $_SESSION['myid'] = $data['userid'];
            if ($_SESSION['myid']) == '': ?>
                <li><a href='?p=login'>Login</a></li>
            <?php endif ?>

            <?php
            if ($_SESSION['level'] == 'admin') {
             echo "<li><a href='?p=useraccount'></a>User Account</li>";
             echo "<li><a href='?p=logout'>Logout</a></li>";
            }
 
            if ($_SESSION['level'] == 'user') {
             echo "<li><a href='?p=notes'></a>Notes</li>";
             echo "<li><a href='?p=chgpass'>Change Password</a></li>";
             echo "<li><a href='?p=logout'>Logout</a></li>";
            }

            if ($_GET['p'] == 'logout') {
             unset($_SESSION['myid']);
             unset($_SESSION['level']);
             header("location: index.php");
            }
            ?>
            </ul>  
        </div>
 
        <div id="content">
        <?php
$page_yang_di_load = isset($_GET['p'])?$_GET['p']:FALSE;
if($page_yang_di_load=='login'){
       include_once('page/login.php');unset($page_yang_di_load);
}
if($page_yang_di_load=='home'){
       include_once('page/home.php');unset($page_yang_di_load);
}
if($page_yang_di_load=='useraccount'){
       include_once('page/useraccount.php');unset($page_yang_di_load);
}
if($page_yang_di_load=='notes'){
       include_once('page/notes.php');unset($page_yang_di_load);
}
if($page_yang_di_load=='chgpass'){
       include_once('page/chgpass.php');unset($page_yang_di_load);
}
 
if(isset($page_yang_di_load)){
       include_once('page/index.php');
} ?>
        </div>
       
        <div id="footer">
            <h4>Hak Cipta &copy 2017 Ricky Atblas Yan. All Right Reserved.</h4>
        </div>
    </div>
 
</body>
</html>



Coba mas yang ini.


<!DOCTYPE html>
<html lang="id">
<head>
	<title>Simple</title>
</head>
<body>
	<form action="" method="post">
		<input type="text" name="Username" />
		<input type="text" name="Password" />
		
		<input type="submit" value="Login" />
	</form>
	
	
</body>
</html>
<?php
session_start();

if(isset($_SESSION["Level"])){
	echo($_SESSION["Level"] == "Admin" ? "You Are Admin DC :p<br /><li><a href='?action=logout'>Logout</a></li>" 
			: // Menggunakan Operator Ternary
		"You Are Normal User<br /><li><a href='?action=logout'>Logout</a></li>");
}

@$Pages = $_GET["action"];
@$Username = $_POST["Username"];
@$Password = $_POST["Password"];

if($Username == "Admin" && $Password == "Admin"){
	$_SESSION["Level"] = $Username;
	die(header("Location: {$_SERVER[PHP_SELF]}"));
	exit();
} elseif($Username == "User" && $Password == "User"){
	$_SESSION["Level"] = $Username;
	die(header("Location: {$_SERVER[PHP_SELF]}"));
	exit();
} else {
	echo "Login Gagal";
}

if(isset($Pages) == "Logout"){
	session_unset($_SESSION["Level"]);
	session_destroy();

	die(header("Location: {$_SERVER[PHP_SELF]}"));
	exit();
}
?>

Semoga bisa dipahami :hmm:

Kalo masih belum paham alur programnya, nanti ane buatin Pseudo Code buat mas :pinter:

Referensi:
1.How session_start() function works?
2.PHP session_start()
3.Session unset() or session_destroy()

[/quote]

Yang benar seperti ini mas.


<?php
if($_SESSION['myid'] == '') : ?>
<li><a href='?p=login'>Login</a></li>
<?php endif ?>

Yang benar seperti ini mas.


<?php
if($_SESSION['myid'] == '') : ?>
<li><a href='?p=login'>Login</a></li>
<?php endif ?>

[/quote]

iya gitu tapi gk bisa broo…
respon nya T_EQUAL ==

iya gitu tapi gk bisa broo…
respon nya T_EQUAL ==
[/quote]

gimana apakah ada penjelasan ?