?
Solved

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

Posted on 2006-05-01
2
Medium Priority
?
203 Views
Last Modified: 2013-12-12
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" >
0
Comment
Question by:mnoel76
2 Comments
 
LVL 16

Accepted Solution

by:
dr_dedo earned 1500 total points
ID: 16581299
you should start as seesion
<?
session_start();
require_once('Connections/myconn.php');
// *** Validate request to login to this site.
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
...........................
.............................
0
 

Author Comment

by:mnoel76
ID: 16581686
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question