continuing help with sessions

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
camhabib
Forum Commoner
Posts: 37
Joined: Tue Aug 16, 2005 8:36 pm
Location: Boston, MA

continuing help with sessions

Post by camhabib »

So I have a somewhat working code for sessions. The code for the login determination page is as follows:

Code: Select all

<?php 

session_start(); 

if (!isset($_SESSION['name'])) { 
  if (isset ($_POST['username'])) {

  $person = $_POST['username']; 
  $pwd = $_POST['password']; 

  $dbusername="abc"; 
  $dbpassword="abc";
  $database="mysql"; 
  mysql_connect($database, $dbusername, $dbpassword); 
  mysql_select_db($database) or die("Unable to connect to database. Please contact the webmaster for further assistance."); 
  
  $query = "SELECT name FROM user_handle.users WHERE uname = '$person' AND  pword  =  '$pwd'";
  $result = mysql_query($query); 

   if (mysql_num_rows($result) != 1) { 
   echo ("Sorry but you are not authorize to view this page. Please check your username and password."); 
   									 } 
 		 else {
 		 $result = $_SESSION[''];
 		 require ('auth_index.html');
 		 		}
  }
  }
  else {
  require ('auth_index.html');
  		}

?>
It connects to the server and finds the entry perfectly, so that is not a problem any longer. The only problem is that it does not set the session name. For example, I wrote this code

Code: Select all

<?php

session_start();
unset ($_SESSION['test']);
$_SESSION['test'] = 'this is a test';
echo ("$_SESSION['test'] is your session name");

?>
and when run nothing happens. No echo is returned. Any ideas on what could be wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you are getting something similar to the following error:

Code: Select all

Parse error: syntax error, unexpected T_STRING in Command line code on line 1
which is due to your usage of the session variable in the echo string.

Code: Select all

echo ("{$_SESSION['test']} is your session name");
Post Reply