Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Help with check login
- <?php
- ini_set('display_errors', 'On');
- error_reporting(E_ALL | E_STRICT);
- $mysqli=new mysqli("localhost", "***", "***","***") ;
- if(!$mysqli){
- die("Database error");
- }
- function checklogin($username, $password){
- global $mysqli;
- $result = $mysqli->prepare("SELECT * FROM users WHERE username = ? and password=?");
- $result->bind_param("ss", $username, $password);
- $result->execute();
- if($result != false){
- $dbArray=$result->fetch();
- if(!$dbArray){
- echo '<p class="statusmsg">The username or password you entered is incorrect, or you haven't yet activated your account. Please try again.</p><br/><input class="submitButton" type="button" value="Retry" onClick="location.href='."'login.php'">";
- return;
- }
- $_SESSION['username']=$username;
- if(isset($_POST['remember'])){
- setcookie("jmuser",$username,time()+60*60*24*356);
- setcookie("jmpass",$password ,time()+60*60*24*356);
- }
- echo'<p class="statusmsg"> You have successfully logged in. You will now be redirected to the homepage.</p>';
- redirect();
- }
- else{
- echo'<p class="statusmsg"> The username or password you entered is incorrect. Please try again.</p><br/>input class="submitButton" type="button" value="Retry" onClick="location.href='."'login.php'">";
- return;
- }
- }
- if(isset($_COOKIE['jmuser']) && isset($_COOKIE['jmpass'])){
- $status=checkCookie($_COOKIE['jmuser'], $_COOKIE['jmpass']);
- if($status==true){
- echo '<p class="statusmsg"> Welcome back '.$_COOKIE['jmuser'].'. You will now be redirected to the homepage.</p>';
- sleep(5);
- redirect();
- }
- }
- else{
- if(isset($_POST['sublogin'])){
- if(( strlen($_POST['user']) >0) && (strlen($_POST['pass']) >0)) {
- checklogin($_POST['user'], $_POST['pass']);
- }
- elseif((isset($_POST['user']) && empty($_POST['user'])) || (isset($_POST['pass']) && empty($_POST['pass']))){
- echo '<p class="statusmsg">You didn't fill in the required fields.</p><br/><input class="submitButton" type="button" value="Retry" onClick="location.href='."'login.php'">";
- }
- }
- else{
- echo '<p class="statusmsg">You came here by mistake, didn't you?</p>';
- }
- }
- <?php
- if(isset($_GET['url'])){
- function redirect() {
- header('location:'.$_GET['url']);
- }
- }
- else {
- function redirect() {
- header('location: index.php');
- }
- }
- ?>
- setcookie("jmuser",$username,time()+60*60*24*356);
- setcookie("jmpass",$password ,time()+60*60*24*356);
Add Comment
Please, Sign In to add comment