w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Restrict page access with member login

try this. login.php

<form action="check.php" method="post">
<table border="0" cellpadding="0" cellspacing="0"
style="margin-left:auto; margin-right:auto;">
<tr><td>Nickname:</td><td><input type="text"
id="usernaame" name="usernaame"></td></tr>
<tr><td>Password:</td><td><input type="password"
id="passworrd" name="passworrd"></td></tr>
<tr><td colspan="2"><input type="submit" value="Login"
class="button"></td></tr></table>
</form>
<br><a
href="register.php"><button>Register</button></a></div>

check.php

<?php
session_start();
$user = htmlspecialchars(addslashes($_POST['usernaame']));
//you can also edit password encryption
$password = htmlspecialchars(addslashes(md5(sha1($_POST['passworrd']))));
//put here your query
$query = mysqli_query();
if(mysqli_num_rows($query)=="1"){
$_SESSION['logged'] = $user;
}
else{echo 'Data is incorrect';}
?>

index.php (where protected content is)

<?php
session_start();
if(!isset($_SESSION['logged'])){echo 'Please login';}
else{
//your private content here
}
?>




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.