I have a Login Page; if username and password match with database will redirect to admin; but on admin page Iam not getting session variables. first my login page:
<?php
session_start(); //Start the session
session_regenerate_id(true);
//print_r($_SESSION);
use Ct\Ct\Data\Data;
extract($_POST);
$eventlists = Data::getpassword();
foreach ($eventlists as $eventlist) {
$get_list_username = $eventlist->user_name;
$get_list_password = $eventlist->user_pass;
}
//echo $get_list_username.'outside';
if(isset($_POST['submit'])) {
$your_name = $_POST['username'];
$your_password = $_POST['password'];
$_SESSION['usr'] = $your_name;
$_SESSION['pwd'] = $your_password;
//echo $_SESSION['username'];
if($_SESSION['usr'] == $get_list_username && $_SESSION['pwd'] == $get_list_password) {
print('<script>window.location.href="https://ct.org/admin-gunpage-update/"</script>');
}
else {
echo '<center><b style="color:red;position: relative;left: -27%;">Invalide username or password, please check again! </b></center>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Login Gun Page Update</title>
</head>
<body>
<form name="login" id="login" method="POST" action="">
<label class="log_in"> LOGIN </label>
<p><label for="username" class="username">Username: </label><input type="text" size="100" name="username" id="username" value="" placeholder="UserName"/></p>
<p><label for="password" class="password">Password: </label><input type="password" size="40" name="password" id="password" value="" placeholder="Password"/></p>
<p><input type="submit" name="submit" id="submit" class="submit" value="Submit"/> <input type="reset" name="reset" id="reset" class="reset" value="reset"/></p>
</form>
</body>
</html>
then admin page:
<?php
session_start(); //Start the session
print_r($_SESSION);
if(!isset($_SESSION['usr'])) // if there is no valid session
{
print('<script>window.location.href="https://ct.org/login-gun-page-updates/"</script>');
//echo 'NOT working !!';
}
echo $_SESSION['usr'];
use Ct\Ct\Data\Data;
extract($_POST);
if(isset($save))
{
Data::getupdate($ticketsavailable);
print('<script>window.location.href="https://ct.org/gun-drawing/"</script>');
}
$ticketleft = "";
$ticketleft = Data::getticketsavailable();
//print_r($ticketleft);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>update page</title>
</head>
<body>
<form action="" method="POST">
<label class="update_heading"> UPDATE TICKETS </label> <a href='https://ct.org/logout-gunpage-update-form/' class="logout_link" > Logout</a><br>
<label for="update" class="update"> Update Number: </label><input type="textbox" id="ticketsavailable" name="ticketsavailable" value="<?php echo $ticketleft[0]->ticket_available; ?>"/><br><br>
<input type="submit" name="save" value="Submit">
</form>
</body>
</html>
I have a Login Page; if username and password match with database will redirect to admin; but on admin page I am not getting session variables. I did print_r($_SESSION);
it shows empty on admin page. And I have started session on both page please help!! please help I am not having time!!
my suggestion is first you login then store username with some user access key in session ex. ($_SESSION['username']=$username);
and store user access in another session variable ($_SESSION['useraccess']="admin");
after login successfully, use this session for other webpage
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.