start_session() help please 
May 21st, 2007, 11:12 PM
| | Needs Regular Fix | | Join Date: May 2007 Location: California
Posts: 348
| | start_session() help please
Hi all, I am new to php and am having trouble with a script. I *think* the problem is with start_session or register_session. Here are the two scripts that I am using. - <?
-
include("inc/config.php");
-
$connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!");
-
$query = "SELECT * FROM clients WHERE name = '$name' AND password = PASSWORD('$password')";
-
$result = mysql_db_query($database, $query, $connection);
-
if (mysql_num_rows($result) == 1)
-
{
-
session_start();
-
-
session_register("client_id");
-
session_register("client_name");
-
session_register("client_email");
-
session_register("client_ref");
-
session_register("client_title");
-
list($clientid, $name, $pass, $email, $ref, $title) = mysql_fetch_row($result);
-
$client_id = $clientid;
-
$client_name = $name;
-
$client_email = $email;
-
$client_ref = $ref;
-
$client_title = $title;
-
-
header("Location: menu.php");
-
mysql_free_result ($result);
-
-
mysql_close($connection);
-
}
-
else
-
-
{
-
mysql_free_result ($result);
-
mysql_close($connection);
-
-
header("Location: index.htm");
-
exit;
-
}
-
?>
and this one.
I can't seem to log into the "admin" area. I know that this issue has to do with the session because in the second script where we have: - <?
-
if ($client_name !== 'admin')
-
{
-
?>
-
<h2>Hello <b>
-
<? echo $client_name ?>
-
</b> </h2>
-
Here are your invoices:
-
-
<?
and after I log in under the admin account, I am not seeing the word "admin" echoed. Does something jump out at anyone? Thanks for looking. Frank
| 
May 22nd, 2007, 04:23 AM
|  | Moderator | | Join Date: Jan 2007 Location: Colombo, Sri Lanka
Posts: 1,421
| |
Please Refer to this link you may find out some solution. http://au3.php.net/session_register | 
May 22nd, 2007, 04:32 AM
| | Needs Regular Fix | | Join Date: May 2007 Location: California
Posts: 348
| |
Its Greek to me... Thanks anyway
EDIT: Actually.. I turned register_globals on and the script worked. What do I need to change in the script to allow the script to function while turning register_globals back off? Thanks again
| 
May 22nd, 2007, 04:42 AM
|  | Moderator | | Join Date: Jan 2007 Location: Colombo, Sri Lanka
Posts: 1,421
| |
If i need to use session in my application I'll make it like this.
[PHP]<?php
//First_page.php
session_start();
$TO_SESS_CLIENT = 'AJAXRAND';
$_SESSION['CLIENT_NAME'] = $TO_SESS_CLIENT;
?>
<a href="2.php">GO</a>[/PHP]
[PHP]<?php
//Second_page.php
session_start();
$FROM_SESS_CLIENT= $_SESSION['CLIENT_NAME'];
if($FROM_SESS_CLIENT == 'AJAXRAND'){
echo 'Hi, '.$FROM_SESS_CLIENT;
}
?>[/PHP]
| 
May 22nd, 2007, 04:45 AM
| | Needs Regular Fix | | Join Date: May 2007 Location: California
Posts: 348
| |
Ajax, thanks a million man.. I think I am seeing that session_register() is depreciated.. Instead, php.net advises to use a global $_session. I am also seeing that in your example as well. Am I correct on this?
I have changed the session_register to $_session["var"]; but I am getting "undefined variable" errors. Here is what that part of the code I made changes to looks like: - if (mysql_num_rows($result) == 1)
-
{
-
session_start();
-
$_session["client_id"];
-
$_session["client_name"];
-
$_session["client_email"];
-
$_session["client_ref"];
-
$_session["client_title"];
-
list($clientid, $name, $pass, $email, $ref, $title) = mysql_fetch_row($result);
-
$client_id = $clientid;
-
$client_name = $name;
-
$client_email = $email;
-
$client_ref = $ref;
-
$client_title = $title;
-
header("Location: menu.php");
-
-
mysql_free_result ($result);
-
mysql_close($connection);
-
}
Thanks again
|  | | Thread Tools | Search this Thread | | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,662 network members.
|