Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > Login page error
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 16th March 15:30
jiuman
External User
 
Posts: 1
Default Login page error



Hi! Im trying to make a login page. I have searched for examples that makes
me check the user name with a database, and the one that suits better is
this code.

<?
session_start(); // start session.
?>
<!-- header tags, edit to match your own, or include template header file. -->
<html>
<head>
<title>Login</title>
<head>
<body>
<?
if(!isset($username) | !isset($password)) {
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?".
$QUERY_STRING;}?>" method="POST">
<p align="center">Members only. Please login to access this do***ent.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="Login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}

// If all is well so far.

session_register("username");
session_register("password"); // register username and password as
session variables.

// Here you would check the supplied username and password against
your database to see if they exist.
// For example, a MySQL Query, your method may differ.

$sql = mysql_query("SELECT password FROM user_table WHERE username =
'$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);

if($numrows != "0" & $password == $fetch_em["password"]) {
$valid_user = 1;
}
else {
$valid_user = 0;
}

// If the username exists and pass is correct, don't pop up the login
code again.
// If info can't be found or verified....

if (!($valid_user))
{
session_unset(); // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?".
$QUERY_STRING;}?>" method="POST">
<p align="center">Incorrect login information, please try again. You
must login to access this do***ent.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="Login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
?>


After this, I have only included on a file that has this code

<?php
include_once 'connection/login.php';
?>


But when I try to see it in a browser I got the error


*Warning*: session_start() [function.session-start
<http://localhost/apache2-default/function.session-start>]: Cannot
send session cache limiter - headers already sent (output started at
/var/www/apache2-default/visual_imag.php:2) in
*/var/www/apache2-default/connection/login.php* on line *2

I have searched for possible answers, and all I have found is that I
should not send any output before the session_start(); But in this
code the session_start(); output is before anything else.
can you give me a tip?

Thanks in advance.
Yamil
*
  Reply With Quote


  sponsored links


2 16th March 15:30
robert
External User
 
Posts: 1
Default Login page error



Look through the source files and make sure you have no spaces or
content preceding <? and no spaces or content trailing ?>

These count as output.

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
  Reply With Quote
3 16th March 15:30
jvalade
External User
 
Posts: 1
Default Login page error


The error comes from having output before the session_start(). This
means that anything before the <? would be output. Even a single empty
space.

Janet


--
Janet Valade -- janet.valade.com
  Reply With Quote
4 16th March 22:18
ceo
External User
 
Posts: 1
Default Login page error


// Perhaps you have a BLANK LINE right here?
// Even a BLANK LINE counts as output.
// Or, perhaps you are include-ing this file from somewhere else?
// ANY output before that include also counts.
// It's also remotely possible that you have an auto_prepend set up.
// That is incredibly unlikely, and mentioned only for completeness sake

Tip:
READ the error message again.

It tells you EXACTLY where the output happened.
[I requested that feature years ago :-)]

Your real problem is in visual_imag.php on line 2.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666