473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

start_session() help please

348 100+
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.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include("inc/config.php");
  3. $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!");
  4. $query = "SELECT * FROM clients WHERE name = '$name' AND password = PASSWORD('$password')";
  5. $result = mysql_db_query($database, $query, $connection);
  6. if (mysql_num_rows($result) == 1)
  7.     {
  8.     session_start();
  9.  
  10.     session_register("client_id");
  11.     session_register("client_name");
  12.     session_register("client_email");
  13.     session_register("client_ref");
  14.     session_register("client_title");
  15.     list($clientid, $name, $pass, $email, $ref, $title) = mysql_fetch_row($result);
  16.     $client_id = $clientid;
  17.     $client_name = $name;
  18.     $client_email = $email;
  19.     $client_ref = $ref;
  20.     $client_title = $title;
  21.  
  22.     header("Location: menu.php");
  23.     mysql_free_result ($result);    
  24.  
  25.     mysql_close($connection);
  26.     }
  27. else
  28.  
  29.     {
  30.     mysql_free_result ($result);    
  31.     mysql_close($connection);
  32.  
  33.     header("Location: index.htm");
  34.     exit;
  35.     }
  36. ?>
and this one.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. session_start();
  3. if(!session_is_registered("client_id"))
  4. {
  5. header("Location: index.htm");
  6. exit;
  7. }
  8. ?>
  9. <html>
  10. <link rel="stylesheet" href="inc/style.css" type="text/css">
  11.  
  12. <body bgcolor="#FFFFFF">
  13. <img src="inc/title.gif" width="308" height="82">
  14. <?
  15. if ($client_name !== 'admin')
  16. {
  17. ?>
  18. <h2>Hello <b> 
  19.   <? echo $client_name ?>
  20.   </b> </h2>
  21.   Here are your invoices:
  22.  
  23. <?
  24. include "inc/dbconnect.php";
  25. include ("inc/date.php");
  26. $result = mysql_query("SELECT * FROM invoices WHERE clientid = '$client_id' ORDER BY $param",$db);
  27. if (!$param) {
  28. $result = mysql_query("SELECT * FROM invoices WHERE clientid = '$client_id' ORDER BY id",$db);
  29. }
  30. echo "<p><table border=1 cellspacing=0 cellpadding=2 bordercolor=#eeeeee width=400>";
  31. echo "<tr align=top><td><b><a href='menu.php?param=id'>Invoice number</a></b></td><td><b><a href='menu.php?param=date'>Date</a></b></td><td><b><a href='menu.php?param=total'>Total</a></b></td><td><b><a href='menu.php?param=status'>Status</a></b></td><td>&nbsp;</td></tr>";
  32.  
  33. while ($row = mysql_fetch_array($result))
  34. {
  35.     $id = $row["id"];
  36.     $date = $row["date"];
  37.     $dateshow = fixDate($date);
  38.     $total = $row["total"];
  39.     $status = $row["status"];
  40.  
  41. if ($alternate == "1") { 
  42.     $color = "#ffffff"; 
  43.     $alternate = "2"; 
  44.     } 
  45.     else { 
  46.     $color = "#efefef"; 
  47.     $alternate = "1"; 
  48.     } 
  49.  
  50. echo "<tr valign=top bgcolor=$color><td>$id</td><td>$dateshow</td><td>$total</td><td>$status</td><td>[ <a href='invoice.php?id=$id'>view</a> ]</td></tr>";
  51. }
  52. echo "</table>";
  53.  
  54. }
  55. elseif ($client_name == 'admin')
  56. {
  57.  
  58. echo "<h2>admin options</h2>";
  59.  
  60. include "inc/dbconnect.php";
  61. include ("inc/date.php");
  62. $result = mysql_query("SELECT * FROM invoices ORDER BY $param",$db);
  63. if (!$param) {
  64. $result = mysql_query("SELECT * FROM invoices ORDER BY id",$db);
  65. }
  66. echo "<p><table border=1 cellspacing=0 cellpadding=2 bordercolor=#eeeeee width=600>";
  67. echo "<tr align=top><td><b><a href='menu.php?param=id'>Invoice number</a></b></td><td><b><a href='menu.php?param=clientid'>Client</a></b></td><td><b><a href='menu.php?param=date'>Date</a></b></td><td><b><a href='menu.php?param=total'>Total</a></b></td><td><b><a href='menu.php?param=status'>Status</a></b></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
  68.  
  69. while ($row = mysql_fetch_array($result))
  70. {
  71.     $id = $row["id"];
  72.     $clientid = $row["clientid"];
  73.     $clientfind = mysql_query("SELECT title FROM clients WHERE clientid = '$clientid'",$db);
  74.     $clienttitle = mysql_result($clientfind,0);
  75.     $date = $row["date"];
  76.     $dateshow = fixDate($date);
  77.     $total = $row["total"];
  78.     $status = $row["status"];
  79.  
  80. if ($alternate == "1") { 
  81.     $color = "#ffffff"; 
  82.     $alternate = "2"; 
  83.     } 
  84.     else { 
  85.     $color = "#efefef"; 
  86.     $alternate = "1"; 
  87.     } 
  88.  
  89. echo "<tr valign=top bgcolor=$color><td>$id</td><td>$clienttitle</td><td>$dateshow</td><td>$total</td><td>$status</td>";
  90. if ($status == 'pending') {
  91. echo "<td>[ <a href='admin_invoice.php?id=$id'>view / change status</a> ]</td>";
  92. }
  93. else {
  94. echo "<td>[ <a href='admin_invoice.php?id=$id'>view</a> ]</td>";
  95. }
  96. echo "<td>[ <a href='notifyclient.php?id=$id'>notify client</a> ]</td><td>[ <a href='edit_invoice.php?id=$id'>edit</a> ]</td><td>[ <a href='delete_invoice.php?id=$id' onClick=\"return confirm('Are you sure?')\">delete</a> ]</td></tr>";
  97. }
  98. echo "</table>";
  99.  
  100. echo "<p><a href='edit_invoice.php'>add an invoice</a> | <a href='clients.php'>manage client profiles</a>";
  101.  
  102.  
  103.  
  104. }
  105. ?>
  106.  
  107. <p><a href="logout.php">Logout</a></p>
  108.  
  109. <?
  110. include "inc/footer.inc";
  111. ?>
  112.  
  113. </body>
  114.  </html>
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:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if ($client_name !== 'admin')
  3. {
  4. ?>
  5. <h2>Hello <b> 
  6.   <? echo $client_name ?>
  7.   </b> </h2>
  8.   Here are your invoices:
  9.  
  10. <?
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 21 '07 #1
4 2718
ak1dnar
1,584 Expert 1GB
Please Refer to this link you may find out some solution.
http://au3.php.net/session_register
May 22 '07 #2
fjm
348 100+
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 22 '07 #3
ak1dnar
1,584 Expert 1GB
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 22 '07 #4
fjm
348 100+
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:

Expand|Select|Wrap|Line Numbers
  1. if (mysql_num_rows($result) == 1)
  2.     {
  3.     session_start();
  4.     $_session["client_id"];
  5.     $_session["client_name"];
  6.     $_session["client_email"];
  7.     $_session["client_ref"];
  8.     $_session["client_title"];
  9.     list($clientid, $name, $pass, $email, $ref, $title) = mysql_fetch_row($result);
  10.     $client_id = $clientid;
  11.     $client_name = $name;
  12.     $client_email = $email;
  13.     $client_ref = $ref;
  14.     $client_title = $title;
  15.     header("Location: menu.php");
  16.  
  17.     mysql_free_result ($result);    
  18.     mysql_close($connection);
  19.     }
Thanks again
May 22 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
0
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from...
4
by: dave | last post by:
Hi guys I display one page in popup window...that fetches some data from sql and perfom some calculation (tht approx 10 secs) and display result.... I am trying to display "Please wait ..."message...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.