|
Posted by Thomas Bonham on 07/11/05 05:50
I have been trying to update & fix the errors.
With the new code (That I will post at the end), I'm only getting one
error and that is that it can't start the session because that it has
been started.
CODE:
<?php
session_start();
if(isset($_POST['username']) && isset($_POST['passwd']))
{
$username = $_POST['username'];
$passwd = $_POST['passwd'];
/* Connecting to database */
$db = pg_connect ("
dbname=auth
user=auth
hostaddr=127.0.01
");
$query = "SELECT * FROM auth_user
WHERE name='$username'
AND
password='$passwd'";
/* Running query */
$result = pg_query($db,$query);
//$rows = pg_num_rows($result);
//$rows->pg_num_rows($result);
if($rows = pg_num_rows($result) > 0)
{
$_SESSION['valid_user'] = $name;
}
else
{
echo 'Failed';
}
}
?>
<html><head><title>Login</title>
<link rel="stylesheet" type="text/css" href="../css/table.css">
<link rel="stylesheet" type="text/css" href="../css/font.css">
</head>
<body>
<table class="center_100">
<tr>
<td class="td_100_center">
<?php
if(isset($_SESSION['valid_user']))
{
echo 'You are logged in as: '.$_SESSION['valid_user'].'<br>';
}
else
{
if(isset($username))
{
echo 'Could not log you in';
}
else
{
echo 'You are not login in.<br>';
}
echo '<form method="post" action="login.php">';
echo 'User Name:';
echo '<input type="text" name="username">';
echo 'Password:';
echo '<input type="text" name="passwd">';
echo '<input type="submit" value="Log in">';
echo '</font>';
}
?>
</td>
</tr>
</table>
</body>
</html>
ERROR:
[client 127.0.0.1] PHP Notice: A session had already been started -
ignoring session_start() in /var/www/html/thomas/cis166ae/data/login.php
on line 3, referer: http://localhost/thomas/cis166ae/data/
[client 127.0.0.1] PHP Notice: A session had already been started -
ignoring session_start() in /var/www/html/thomas/cis166ae/data/login.php
on line 3, referer: http://localhost/thomas/cis166ae/data/login.php
[client 127.0.0.1] PHP Notice: Undefined variable: name in
/var/www/html/thomas/cis166ae/data/login.php on line 29, referer:
http://localhost/thomas/cis166ae/data/login.php
[Sun Jul 10 19:44:57 2005] [error] [client 127.0.0.1] File does not
exist: /var/www/html/favicon.ico
Thx
Thomas
Thomas Bonham wrote:
> Using the examples for php and my book.
> This is the error that I get with the following code.
>
> ERROR:
> [client 127.0.0.1] PHP Warning: session_start(): Cannot send session
> cookie - headers already sent by (output started at
> /var/www/html/thomas/cis166ae/data/login.php:2) in
> /var/www/html/thomas/cis166ae/data/login.php on line 3, referer:
> http://localhost/thomas/cis166ae/data/
> [client 127.0.0.1] PHP Warning: session_start(): Cannot send session
> cache limiter - headers already sent (output started at
> /var/www/html/thomas/cis166ae/data/login.php:2) in
> /var/www/html/thomas/cis166ae/data/login.php on line 3, referer:
> http://localhost/thomas/cis166ae/data/
> [client 127.0.0.1] PHP Warning: session_start(): Cannot send session
> cookie - headers already sent by (output started at
> /var/www/html/thomas/cis166ae/data/login.php:2) in
> /var/www/html/thomas/cis166ae/data/login.php on line 3, referer:
> http://localhost/thomas/cis166ae/data/login.php
> [client 127.0.0.1] PHP Warning: session_start(): Cannot send session
> cache limiter - headers already sent (output started at
> /var/www/html/thomas/cis166ae/data/login.php:2) in
> /var/www/html/thomas/cis166ae/data/login.php on line 3, referer:
> http://localhost/thomas/cis166ae/data/login.php
> [client 127.0.0.1] PHP Fatal error: Call to a member function on a
> non-object in /var/www/html/thomas/cis166ae/data/login.php on line 23,
> referer: http://localhost/thomas/cis166ae/data/login.php
> [Sun Jul 10 18:33:02 2005] [error] [client 127.0.0.1] File does not
> exist: /var/www/html/favicon.ico
> [root@thomas httpd]#
>
>
> CODE:
>
>
> <?php
> session_start();
>
> if(isset($_POST['username']) && isset($_POST['passwd']))
> {
> $username = $_POST['username'];
> $passwd = $_POST['passwd'];
>
> /* Connecting to database */
> $db = pg_connect ("
> dbname=auth
> user=auth
> hostaddr=127.0.01
> ");
> $query = "SELECT * FROM auth_user
> WHERE name='$username'
> AND
> password='$passwd'";
>
>
> /* Running query */
> $result->pg_query($query);
> $rows = pg_num_rows($result);
> if($rows > 0)
> {
>
> $_SESSION['valid_user'] = $name;
>
> }
> else
> {
> echo 'Failed';
> }
> }
> ?>
> <html><head><title>Login</title>
> <link rel="stylesheet" type="text/css" href="../css/table.css">
> <link rel="stylesheet" type="text/css" href="../css/font.css">
> </head>
> <body>
> <table class="center_100">
> <tr>
> <td class="td_100_center">
>
> <?php
>
> if(isset($_SESSION['valid_user']))
> {
> echo 'You are logged in as: '.$_SESSION['valid_user'].'<br>';
> }
> else
> {
> if(isset($username))
> {
> echo 'Could not log you in';
> }
> else
> {
> echo 'You are not login in.<br>';
> }
>
> echo '<form method="post" action="login.php">';
> echo 'User Name:';
> echo '<input type="text" name="username">';
> echo 'Password:';
> echo '<input type="text" name="passwd">';
> echo '<input type="submit" value="Log in">';
> echo '</font>';
> }
> ?>
>
>
>
> </td>
> </tr>
> </table>
>
> </body>
> </html>
>
>
> Thanks
> Thomas
>
> On 7/10/05, Richard Lynch <ceo@l-i-e.com> wrote:
>
>>On Sat, July 9, 2005 8:27 pm, Thomas Bonham said:
>>
>>>If someone can send me a example of a login sesson.
>>
>>http://php.net/session_start
>>
>>--
>>Like Music?
>>http://l-i-e.com/artists.htm
>>
>>
>>
>
>
>
Navigation:
[Reply to this message]
|