I'm trying use the script( and html page) to below to set session
variables, but
keep getting the follow errors:
NOTE: I seen several posting re: using $HTTP_SESSION_VAR is another case
where
that would apply?
Thanks in advance,
David Jackson
---------------- Browser Error Messages ---------------------
Warning: Cannot send session cookie - headers already sent by (output
started at
/home/sites/site13/web/connect.php:13) in
/home/sites/site13/web/frontdesk/sales/login.php on line 15
Warning: Cannot send session cache limiter - headers already sent (output
started at
/home/sites/site13/web/connect.php:13) in
/home/sites/site13/web/frontdesk/sales/login.php on line 15.
------------------- login.php ---------------------------------
<?php include("/home/sites/www.pickledbeans.com/web/connect.php"); ?>
<?php
$result = mysql_query("SELECT uid,uname,uperms FROM guestusers
WHERE uname = '$uname'
AND upass = PASSWORD('$upass')");
if (mysql_num_rows($result)!=1) {
echo "Dis ain't good !!\n";
mysql_free_result ($result);
mysql_close($link);
} else {
// start session
session_start();
session_register("Uid");
session_register("Uname");
session_register("Uperms");
// parse out query output and resign to session vars
list($uid,$uname,$uperms) = mysql_fetch_row($result);
$Uid = $uid;
$Uname = $uname;
$Uperms = $uperms;
// redirect to main menu page
mysql_free_result ($result);
mysql_close($link);
----------------- login.html ------------------------
<html>
<head>
<title>Generic Time Tracker</title>
</head>
<h3>Sales Entry Login screen:</h3>
<table border="0" cellspacing="5" cellpadding="5">
<form action="login.php" method="post">
<tr>
<td>Username:</td>
<td><input type="Text" name="uname" size="15"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="upass" size="15"></td>
</tr>
<tr>
<td colspan="2" align="CENTER"><input type="Submit" name="submit"
value="Enter"></td>
</tr>
</form>
</table>
</body>
</html>
--
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general...@lists.php.net
> For additional commands, e-mail: php-gene...@lists.php.net
> To contact the list administrators, e-mail: php-lis...@lists.php.net
>
>
Cookies are set and read via HTTP headers, therefore this has to occur
before any output is sent to the client. You can work around this with the
ob_start() and ob_end_flush() functions, but normally you'd want to move
the session_start() or session_register() calls up to the top of your
script. See below:
"Note: If you are using cookie-based sessions, you must call
session_start() before anything is output to the browser."
http://www.php.net/manual/en/function.session-start.php
"Note: In PHP 4, you can use output buffering to get around this problem,
with the overhead of all of your output to the browser being buffered in
the server until you send it. You can do this by calling ob_start() and
ob_end_flush() in your script, or setting the output_buffering
configuration directive on in your php.ini or server configuration files."
Fred
Duane Douglas <ddou...@mindspring.com> wrote in message
news:4.2.0.58.2001122...@europa.your-site.com...
> hello,
>
> i have an apache rpm installed. stuff will break if i uninstall it. how
> do i install php to work with it?
>
> tia
>
> Duane Douglas
> ASP / SQL Server Tutoring and Training
>
thanks for the link. unfortunately, the rpm packages there don't work with
rh linux 7.2. does anyone have another suggestion?
Thanks for your time and knowledge,
David Jackson
----- login.php -----------
<?php
// start session
session_start();
session_register("Uid");
session_register("Umid");
// Connect to db
include("/home/sites/www.pickledbeans.com/web/connect.php");
// insert new user
$result = mysql_query("SELECT id,mid,name,perms FROM staff
WHERE name = '$frm_name'");
if (mysql_num_rows($result)!=1) {
echo "Dis ain't good !!\n";
echo "<html><body>";
echo "<meta http-equiv=\"refresh\" content=\"5;
url=http://backoffice.pickledbeans.com/index.html\">";
echo "</body></html>";
mysql_free_result ($result);
mysql_close($link);
} else {
echo "We have winner:\n";
// parse out query output and resign to session vars
list($id,$mid,$name) = mysql_fetch_row($result);
echo "<p>$id</p>";
echo "<p>$name</p>";
$Uid = $id;
$Umid = $mid;
$Uname = $name;
// redirect to main menu page
mysql_free_result ($result);
mysql_close($link);
echo "<html><body>";
echo "<meta http-equiv=\"refresh\" content=\"5;
url=http://backoffice.pickledbeans.com/sales.html\">";
echo "</body></html>";
}
?>
---------- sales.php ---------------
<?php
// If sesssion vars don't exist, goto login form
// else display sales data entry form
session_start();
// if(!session_is_registered("Uid")) {
// echo "<p>We need to goto login screen!!</p>";
// } else {
echo "<p>Session uid set to:$Uid</p>\n";
echo "<p>Session uid set to:$Umid</p>\n";
echo "<p>Session date: $frm_date</p>\n";
echo "<p>Session amount set to: $frm_amount</p>\n";
//
include("/home/sites/www.pickledbeans.com/web/connect.php");
// Insert Sales data into sales table
mysql_query("INSERT INTO sales(id,mid,date,amount)
VALUES('$Uid','$Umid','$frm_date','$frm_amount')") ;
mysql_close($link);
echo "<html><body>";
echo "<meta http-equiv=\"refresh\" content=\"5;
url=http://backoffice.pickledbeans.com/sales.html\">";
echo "</body></html>";
?>
Thanks,
David
--
Out of habit, I abstract all of the MySQL functions to handle this. My
current setup for http://hosting.venura.net/ (still under construction).
outputs error messages like this:
function sqlQuery($query, $secure = 0) {
$result = mysql_query($query);
if(!$result) {
if($secure) {
$query = '*** hidden ***';
}
else {
/* This is just an oddity from how I construct some queries, primarily
INSERTs. If all of your queries are on a single line of text with no
leading/trailing whitespace or you don't care about appearance, you can
delete this section of the code */
$query = explode("\n", $query);
foreach($query as $line => $text) {
$query[$line] = trim($text);
}
$query = implode("\n", $query);
}
die('<h1>Oops...</h1><p><b>Sorry, but something seems to have gone
terribly wrong...</b></p>
<pre>
MySQL Error Number: ' . htmlspecialchars(mysql_errno()) . '
MySQL Error Description: ' . htmlspecialchars(mysql_error()) . '
Query Text:
' . htmlspecialchars($query) . '
</pre>
<p>(Yes, you probably have found a bug.)</p>
');
} else return ($result);
}
This will dump the query, error number and error description whenever a SQL
query fails. You can set the optional second parameter ($secure) to true if
your query involves anything that you don't want the end-user to see, such
as updating a password or something like that.
disclaimer: I didn't check to see what database engine you're using. If
you're using MySQL, this should work, otherwise use something similiar.