HOME / BLOG / BLOG-POST

Basic login function example in php?

Basic login function example in php

//redirect to dashboard if session is active code

session_start();
if(isset($_SESSION['ID'])){
dashboard(); 
}
//dashboard redirect code used in function.php

function dashboard(){
 echo '<script LANGUAGE="JavaScript">window.location.href="'.site_url().'/dashboard/";</script>';
 }


//php code

if(isset($_POST['login'])){
 
 extract($_POST);
 
 
 
 global $wpdb;
 $table_name = $wpdb->prefix . "shopkeeper_signup";
 $results = $wpdb->get_results("select * from $table_name where phonenumber LIKE BINARY '$phonenumber' and pass LIKE BINARY '$pass'");
 

 
 foreach($results as $result)
 {
  $phone = $result->phonenumber;
 }

 
 
 if((count($results)) > 0 ){
  session_start();                           //session started here
  $_SESSION['ID']=$phone;
  return dashboard();
 }
 else
 {
  $msg = "Username or Password is wrong!<br>click here to <a style='color:#FFEB3B' href=".site_url().">login</a> again";
 }
 
 
 
}

 


about authors

Sandip Das

Web Developer

Once a legend said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler.



POST COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *