Saturday, November 26, 2016

Admin Panel

session_start(); ai funtion ta kono file a daoya mane session start hoise.
justify:
akta file ex: index.php a
session_start();
$_SESSION['ranit'] = "designer";
akta value sate kori, session start and akta value add hoya jabe. akon jodi ar akta file another.php te
just echo $SESSION['ranit']; kori kaj korbe na. session_start(); korte value ta show korbe. Ata holo index.php run hoyar karon a. jodi browser kase dai just another.php run kori notice show korbe , mane se value ta paitase na. karaon index.php ta run kora hoy nai tai another.php  value ta collect korte parse na.

session_destroy(); je file a use korbo ai file browser ar por ar onno file gulo kaj korbe na.
tai je file a value set koraci oi file a aste hobe then abar session start hobe then kaj korbo.

session ar age koto kisu add korbo na. Ata first a thakbe,

Login and Logout:
admin name ak ta folder asa. 3 ta file login, logout, index.php .
index.php te :
akta form add korlam:

index.php te:
// print_r($_POST);

session_start();
if(isset($_POST['email'])){
$email = $_POST['email'];
$_SESSION['email']= $email;
}
if(isset($_POST['password'])){
$password = $_POST['password'];
$_SESSION['password']= $password;
}
if(isset($_POST['email'])){
echo $email;
}


?>
admin.php te:
session_start();

echo $_SESSION ['email'];
echo $_SESSION ['password'];

tahole: value gulo admin.php te show korbe. 
but direct admin.php browse korle error show korbe karon akane  isset kora asa. tai age input dite hobe. 

jodi

// print_r($_POST);

session_start();
if(isset($_POST['email'])){
$email = $_POST['email'];
$_SESSION['email']= $email;
}
if(isset($_POST['password'])){
$password = $_POST['password'];
$_SESSION['password']= $password;
}
if(isset($_POST['email'])){
echo $email;
}
if(isset($_POST['login-form'])){
header('location:admin.php');
}

?>
set kori tahole submit korar kor admin.php te chole jaibe. because ami location set koraci. akone location ar l small or capital kono problem na and admin.php at age space dite hobe atao kono problem na. 
but direct admin.php browse korle error show korbe karon akane  isset kora asa. tai age input dite hobe. tai redistrict korbo 
logout.php te: 
session_start();
session_destroy();


solve index.php te 2 ta variable nibo:
$email = "rntprince@gmail.com";
$password="amivaloasi";

and admin.php te:
session_start();

// echo $_SESSION ['email'];
// echo $_SESSION ['password'];

if(isset($_SESSION['email'])){

echo "it's setup";
}
else{
header('location: index.php');
}

tahole amra jodi logout open kori then admin.php tai ata direct index.php te redirect korbe. 

akon ami jodi boli je ami variable 2 ta index.php te nai. email ar password set kori je a gulo sara onno input dile kaj korbe na,
session_start();

// echo $_SESSION ['email'];
// echo $_SESSION ['password'];

$un = "rntprince60@gmail.com";
$pass ="amivaloasi";
if( isset($_SESSION['email']) == $un && $_SESSION['password'] == $pass){
echo "setup";
}
else{
   header('location: index.php');
 }
tahole just oi email ar pass dite hobe ta na hole kaj korbe na,

Full code:
index.php that mean our website:
admin.php:
session_start();

// echo $_SESSION ['email'];
// echo $_SESSION ['password'];

$un = "rntprince60@gmail.com";
$pass ="amivaloasi";
if( isset($_SESSION['email']) == $un && $_SESSION['password'] == $pass){
echo "

Welcome in our admin Panel

";
}
else{
   header('location: index.php');
 }
?>



index.php
// print_r($_POST);

session_start();
$un = "rntprince60@gmail.com";
$pass ="amivaloasi";
if(isset($_POST['email'])){
$email = $_POST['email'];
$_SESSION['email']= $email;
}  
if(isset($_POST['password'])){
$password = $_POST['password'];
$_SESSION['password']= $password;
}
if(isset($_POST['email'])){
echo $email;
}
if(isset($_POST['login-form'])){
header('location: admin.php');
}
if( isset($_SESSION['email']) == $un && $_SESSION['password'] == $pass){
header('location: admin.php');
}
?>


logout.php:
session_start();
session_destroy();
 header('location: index.php');





0 comments:

Post a Comment