Re: [PHP-DB] Queries close session
Adept-Hosting.Net Administration wrote: I am using the following script to maintain a login session on some pages: ?php session_start(); if(empty($_SESSION['username'])) { die('An error has ocurred. It may be that you have not logged in, or that your session has expired. Please try a href=index.phplogging in/a again or contact the a href=mailto:[EMAIL PROTECTED]system administrator/a'); } ? The sessions are stable and work fine EXCEPT when I run another PHP script on the web page such as: the script below does not call session_start()- you must call session_start() on each request that you need the session data, normally people put all their session check/start-up stuff in a seperate file and then include that when needed: ? require db_connect.inc; require session.inc; // do you queries and output the results etc! ?php // Make a MySQL Connection require db_connect.inc; // Retrieve all the data from the example table $result = mysql_query(SELECT * FROM members WHERE Status='Inactive') or die(mysql_error()); echo table border='1' cellpadding='0' cellspacing='1' align='center'; echo tr thCertificate #/ththDan rank/ththFirst Name/th thLast Name/th /tr; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo trtd; echo $row['Cert_number']; echo /tdtd; echo $row['Dan_rank']; echo /tdtd; echo $row['First']; echo /tdtd; echo $row['Last']; echo /td/tr; } echo /table; ? I'm assuming that I am either not maintaining the session properly or not linking the scripts to the session. Any pointers on how to accomplish what I'm trying to do? Thanks, - Ken -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Queries close session
normally people put all their session check/start-up stuff in a seperate file and then include that when needed: ? require db_connect.inc; require session.inc; Of course, you would want to make sure any of your included PHP files have the .php (or equivilant) extension, thus preventing your server from serving their full contents to people who would request them directly (as the server won't know to parse them as PHP scripts). -- Matt Ferris [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Queries close session
Because the session you are using probably uses a cookie to remember the session, it is required that you call session_start before you output anything to the screen(aka: send any headers). So if you place the session start at the very top of your page before you include any files or output anything, the session should work. Beware of any whitespace before the ?php tags because that will also send headers. Calvin On Mon, 14 Mar 2005 14:55:53 -0700, Adept-Hosting.Net Administration [EMAIL PROTECTED] wrote: I am using the following script to maintain a login session on some pages: ?php session_start(); if(empty($_SESSION['username'])) { die('An error has ocurred. It may be that you have not logged in, or that your session has expired. Please try a href=index.phplogging in/a again or contact the a href=mailto:[EMAIL PROTECTED]system administrator/a'); } ? The sessions are stable and work fine EXCEPT when I run another PHP script on the web page such as: ?php // Make a MySQL Connection require db_connect.inc; // Retrieve all the data from the example table $result = mysql_query(SELECT * FROM members WHERE Status='Inactive') or die(mysql_error()); echo table border='1' cellpadding='0' cellspacing='1' align='center'; echo tr thCertificate #/ththDan rank/ththFirst Name/th thLast Name/th /tr; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo trtd; echo $row['Cert_number']; echo /tdtd; echo $row['Dan_rank']; echo /tdtd; echo $row['First']; echo /tdtd; echo $row['Last']; echo /td/tr; } echo /table; ? I'm assuming that I am either not maintaining the session properly or not linking the scripts to the session. Any pointers on how to accomplish what I'm trying to do? Thanks, - Ken -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Queries close session
Thanks for the quick reply. That doesn't seem to be the problem, though, as I can't seem to find any additional spaces being sent in the headers. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Calvin Lough Sent: March 14, 2005 3:07 PM To: Adept-Hosting.Net Administration; php-db@lists.php.net Subject: Re: [PHP-DB] Queries close session Because the session you are using probably uses a cookie to remember the session, it is required that you call session_start before you output anything to the screen(aka: send any headers). So if you place the session start at the very top of your page before you include any files or output anything, the session should work. Beware of any whitespace before the ?php tags because that will also send headers. Calvin On Mon, 14 Mar 2005 14:55:53 -0700, Adept-Hosting.Net Administration [EMAIL PROTECTED] wrote: I am using the following script to maintain a login session on some pages: ?php session_start(); if(empty($_SESSION['username'])) { die('An error has ocurred. It may be that you have not logged in, or that your session has expired. Please try a href=index.phplogging in/a again or contact the a href=mailto:[EMAIL PROTECTED]system administrator/a'); } ? The sessions are stable and work fine EXCEPT when I run another PHP script on the web page such as: ?php // Make a MySQL Connection require db_connect.inc; // Retrieve all the data from the example table $result = mysql_query(SELECT * FROM members WHERE Status='Inactive') or die(mysql_error()); echo table border='1' cellpadding='0' cellspacing='1' align='center'; echo tr thCertificate #/ththDan rank/ththFirst Name/th thLast Name/th /tr; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo trtd; echo $row['Cert_number']; echo /tdtd; echo $row['Dan_rank']; echo /tdtd; echo $row['First']; echo /tdtd; echo $row['Last']; echo /td/tr; } echo /table; ? I'm assuming that I am either not maintaining the session properly or not linking the scripts to the session. Any pointers on how to accomplish what I'm trying to do? Thanks, - Ken -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php