Login form fails after login
Posted: Tue Mar 21, 2017 6:20 am
Hello,
I have used it in the past but trying to use it again, it fails.
I have a Login form, and depending on the user visiting the first time, I am trying to redirect them to the Edit profile page to force them to change the password.
Here is partial code of the login form, followed by the partial code of editprofile.php, in RED is the section the causes it to fail, why?
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'loginform')
{
$success_page = './PreviousNewsletters.php';
$error_page = './editprofile.php';
$database = './memberslogin.php';
$crypt_pass = md5($_POST['password']);
$found = false;
$fullname = '';
$session_timeout = 600;
if(filesize($database) > 0)
{
$items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($items as $line)
{
list($username, $password, $email, $name, $active) = explode('|', trim($line));
if ($username == $_POST['username'] && $active != "0" && $password == $crypt_pass)
{
$found = true;
$fullname = $name;
}
}
}
And here below is the editprofile.php - it fails on this : if (!isset($_SESSION['username'])) - as if it doesn't know about the variable username.
I tried even adding at the top of the page : <?php echo $username; ?>, that didn't help me either...
<?php
if (session_id() == "")
{
session_start();
}
if (!isset($_SESSION['username']))
{
$accessdenied_page = './denied.html';
header('Location: '.$accessdenied_page);
exit;
}
I have used it in the past but trying to use it again, it fails.
I have a Login form, and depending on the user visiting the first time, I am trying to redirect them to the Edit profile page to force them to change the password.
Here is partial code of the login form, followed by the partial code of editprofile.php, in RED is the section the causes it to fail, why?
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'loginform')
{
$success_page = './PreviousNewsletters.php';
$error_page = './editprofile.php';
$database = './memberslogin.php';
$crypt_pass = md5($_POST['password']);
$found = false;
$fullname = '';
$session_timeout = 600;
if(filesize($database) > 0)
{
$items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($items as $line)
{
list($username, $password, $email, $name, $active) = explode('|', trim($line));
if ($username == $_POST['username'] && $active != "0" && $password == $crypt_pass)
{
$found = true;
$fullname = $name;
}
}
}
And here below is the editprofile.php - it fails on this : if (!isset($_SESSION['username'])) - as if it doesn't know about the variable username.
I tried even adding at the top of the page : <?php echo $username; ?>, that didn't help me either...
<?php
if (session_id() == "")
{
session_start();
}
if (!isset($_SESSION['username']))
{
$accessdenied_page = './denied.html';
header('Location: '.$accessdenied_page);
exit;
}