Jump to content

Recommended Posts

I am trying to set 3 sessions upon login but when I try to echo the session info on the following page it doesn't do anything.  Here is my login form and below that is where I am trying to call the session on the following page.  Any assistance would be greatly appreciated!!!

 

<?php 
session_start();
require_once('../Connections/prbc.php');

if(isset($_POST['login'])){
$username = '';
$password = '';

if (isset ($_POST['username']) && $_POST['username'] != '')

$username = $_POST['username'];

if(isset ($_POST['password']) && $_POST['password'] != '')

$password = $_POST['password'];

$username = mysql_real_escape_string( $username );
$password = mysql_real_escape_string( $password );

$db_password = md5($password);

mysql_select_db('prbcweb') or die(mysql_error());
$login = mysql_query("SELECT * FROM prbc_user WHERE `user_name` = '$username' AND `user_pass` = '$db_password'");
$row_login = mysql_fetch_array($login);
$row_login_total = mysql_num_rows($login);

if ($row_login_total == 1) {
$_SESSION['MM_Username'] = $row_login['user_name'];
$_SESSION['UID'] = $row_login['user_id'];
$_SESSION['auth_level'] = $row_login['user_access_level'];
header("Location: approver.php");

} elseif ($row_login_total <> 1) {
header("Location: login_2.php");
}
}
?> 

 

Second Page

 

<?php
session_start();
if(isset($_SESSION['MM_Username']))
{echo $_SESSION['MM_Username'];
}
?>

You need only one session and perhaps the auth one if you think thats handy. Just use user_id.

 

If you want to give every client a unique ID, dont use IP address, but sessions with a random id...IP address might be the same of different clients...ie a lan.

 

FD

So, I can't set multiple sessions?  Even if I take the other two out and just use this on the next page

 

<?php
session_start();
echo $_SESSION['MM_Username'];
?>

 

I am still getting an error:

 

Notice: Undefined index: MM_Username in C:\root\admin\approver.php on line 3

 

<?php
session_start();

if (!isset($_SESSION['MM_Username'])) {
      $_SESSION['MM_Username'] = 'Test Name';
      echo '<a href="' . $_SERVER['PHP_SELF'] . '">Click Here</a>';
}else {
     echo "It Worked!!!<br />MM_Username = " . $_SESSION['MM_Username'];
}
?>

 

You are not defining the variable $_SESSION['MM_Username']  before you call it, and since there is no definition for that index, php sees it as undefined and thus throws a "Notice" error.

I was trying to assign it on the page before.  Is that not going to stay from page to page?

 

if ($row_login_total == 1) {
$_SESSION['MM_Username'] = $row_login['user_name'];
$_SESSION['UID'] = $row_login['user_id'];
$_SESSION['auth_level'] = $row_login['user_access_level'];
header("Location: approver.php");

The header tag tends to throw off setting session variables. Suggest a Javascript or Meta redirect.

 

if ($row_login_total == 1) {
$_SESSION['MM_Username'] = $row_login['user_name'];
$_SESSION['UID'] = $row_login['user_id'];
$_SESSION['auth_level'] = $row_login['user_access_level'];
echo "<script type=text/javascript>location.href='approver.php'</script>";

 

Should work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.