|
lesson 47.php
|
|
|
user visibke
|
we will run this page
|
|
<?php
|
|
|
require 'core.php';
|
template
|
|
require 'lesson44.php';
|
template
|
|
//include login , if we write outside the below if, it show s in
or out of looged in, always shos logged in, for that purpose we will show
|
|
|
|
|
|
if (loggedin()){
|
in core page we used core
|
|
echo 'you are logged in!';
|
if written true, it will execute this loggedin
|
|
}else{
|
|
|
include 'login.php';
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
?>
|
|
|
how to get the required row header related to username
|
|
|
how to logout the webpage after login
|
|
|
core.php
|
|
|
<?php
|
|
|
ob_start();
|
|
|
//to use header we have to start this
|
|
|
session_start();
|
|
|
$current_file =
$_SERVER['SCRIPT_NAME'];
|
|
|
//IT WILL Bcarry basic data - it will give the url withoud
domainname /login.php
|
|
|
function loggedin(){
|
|
|
if (isset($_SESSION['user_id']) &&
!empty($_SESSION['user_id'])){ return true;}
|
|
|
else{return false;}
|
|
|
}
|
|
|
function getuserfield($field){
|
write a function w
|
|
global $mycon;
|
|
|
$id = $_SESSION['user_id'];
|
get the id of that sesion and load into variable of that id
|
|
$query = "SELECT `$field` FROM `users` WHERE `id` = '$id'
";
|
run the query to , we gpt the one variable data, programm is
asking row heading that’s want to get that and filters id of the required
|
|
if($query_run = mysqli_query($mycon, $query)){
|
run this query against database
|
|
$num_rows =
mysqli_num_rows($query_run);
|
count the number of rows of that id with username
|
|
if($num_rows == 1)
|
if rows one ,
|
|
{$row = mysqli_fetch_row($query_run);
|
convert that row into array
|
|
return $row[0];
|
return that row with zero index
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
?>
|
|
|
logout.php
|
|
|
<?php
|
|
|
// session variable destroyed, session list empty, then core
page , shows unset, it returns false, thne shows login page
|
|
|
require 'core.php';
|
to logout , stored session have to destroy
|
|
session_destroy();
|
|
|
header ('location: lesson47.php')
|
after destroy, it loads to this page , redirects
|
|
// after session destroyed go to this page means change in url
with this name in ends
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
user page
|
|
|
<?php
|
|
|
require 'core.php';
|
|
|
require 'lesson44.php';
|
|
|
//include login , if we write outside the below if, it show s in
or out of looged in, always shos logged in, for that purpose we will show
|
|
|
$logout_text = '<br><a
href="logout.php">logout </a>';
|
after log out,it have to logout page
|
|
if (loggedin()){
|
|
|
$firstname = getuserfield('firstname');
|
get the firstname of entered usernamae
|
|
$secondname = getuserfield('surname');
|
get the firstname of entered username
|
|
echo 'welcome, '.$firstname.' '. $secondname .' '.$logout_text ;
|
concatenate
|
|
}else{
|
|
|
include 'login.php';
|
if not , redirects to loginpage
|
|
}
|
|
|
?>
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No comments:
Post a Comment