Avatar of mnoel76
mnoel76

asked on 

Need help enabling session_start variable.....it does not seem to be working properly??

I have a login page that should check to see if the user is authenticatedor logged in when the user clicks 'My Account' button but it is just reloading the login page even though in the top left corner of the page it shows user is logged in.  

What should happen is it check of there is a session variable and if so take that user to his account info.  if not it should load the login.php page

Can you look at the code to see whats going on...dont quiet understand what going on in this login form.

Thanks

<?php
require_once('Connections/myconn.php');
// *** Validate request to login to this site.
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['memberId']);
session_unregister('MM_Username');
session_unregister('MM_UserGroup');
session_unregister('memberId');

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
  session_register('PrevUrl');
  $_SESSION['PrevUrl'] = $accesscheck;
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "login_check.php";
  $MM_redirectLoginSuccess = "memberindex.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_myconn, $myconn);
 
  $LoginRS__query=sprintf("SELECT id,email,name, password FROM members WHERE email='%s' AND password='%s' and active = 'Yes' ",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
   
  $LoginRS = mysql_query($LoginRS__query, $myconn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
        //admin type
     $loginStrGroup = "MEMBER";
   
      $array = mysql_fetch_assoc($LoginRS);
      //$GLOBALS['memberID'] = $array['id'];
      //$GLOBALS['memberName'] = $array['name'];
      
    //declare two session variables and assign them
   // $GLOBALS['MM_Username'] = $loginUsername;
   // $GLOBALS['MM_UserGroup'] = $loginStrGroup;      
        
    //register the session variables
    session_register("MM_Username");
      $_SESSION['MM_Username'] = $loginUsername;
    session_register("MM_UserGroup");
      $_SESSION['MM_UserGroup'] = $loginStrGroup;
      session_register("memberID");
      $_SESSION['memberID'] = $array['id'];
      session_register("memberName");
      $_SESSION['memberName'] = $array['name'];

      mysql_query('update members set last_login = NOW() where id = '.$array['id'],$myconn) or die(mysql_error());
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];      
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
include('header.php');
?>
<FORM ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" >
PHP

Avatar of undefined
Last Comment
mnoel76
ASKER CERTIFIED SOLUTION
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mnoel76
mnoel76

ASKER

dr dedo....thanks for the response.  I tried that but it didn't give me the result I was looking for.  I did find a work around which basically looks to see if there is a session variable and dependent on if there is or is not....the user then when he  clicks the my account will take him to the correct page.  As opposed to loading the login page.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo