session_register()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

session_register()

Post by rats »

having a bit of trouble with if(session_register($SESSION_UID)){ which says its "successful" but the $SESSION_UID is not advailable on pages after this one.... ...not sure why..I have removed most of the functions to keep it simple...

Code: Select all

<?php
include"config.inc";
require_once("DB.php");
session_start();
$formuser = $HTTP_POST_VARSї'formuser'];
$formpass = $HTTP_POST_VARSї'formpass'];
$formemail = $HTTP_POST_VARSї'formemail'];

function loginUser($name, $pass)
{
  global $host, $user, $password, $database;
  $epass = encrypt($pass);
  $db = new DB($host, $user, $password, $database);
  //open a connection
  if(!$db->open()){
    die($db->error());
  }
  if(!$db->query("SELECT id FROM user WHERE username = '$name' AND password = '$epass'")){
    die($db->error());
  }
  // if row exists - login/pass is correct
  if ($db->numRows()== 1)
  {
    // register the user's ID
    list($id) = $db->fetchArray();
    session_start();
    $SESSION_UID = $id;
    if(session_register($SESSION_UID)){
      echo ("success");
    }else{
      echo ("failed");
    }
  }
  echo $db->numRows();
  $db->freeResult();
  $db->close();
}

function encrypt($item)
{
  return (md5($item));
}

switch($HTTP_GET_VARSї'act'])
{
  case "login":
    loginUser($formuser, $formpass);
    break;
  case "logout":
    logoutUser();
    break;
  case "new":
    newUser($formname, $formpass, $formemail);
    break;
  case "update":
    updateUser($SESSION_UID);
    break;
  case "view":
    viewUser($formname);
    break;
  case "delete":
    viewUser($formname);
    break;
  default:
    //if they havent specified an action send them to index.php
    header("Location: http://avalon/");
    exit();
}
?>
ozmodiar
Forum Commoner
Posts: 35
Joined: Sat Jun 01, 2002 6:29 am
Location: Dublin, Ireland

Post by ozmodiar »

You must call session_start() at the top of each page where you want to use the session variable.

Dunno if this is the problem maybe you have been doing this.
What version of PHP are you using?
Post Reply