Login problem

Links for php scripts

Moderators: macek, egami, gesf

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Login problem

Postby kiwi » Mon Jul 19, 2004 12:11 am

i get a login code, and i modified it to fit my project, i can use it. I can login , but after i login , this error message show in the page:

Warning: session_register(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\opbs\member.php:1) in c:\inetpub\wwwroot\opbs\member.php on line 20

Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\opbs\member.php:1) in c:\inetpub\wwwroot\opbs\member.php on line 20


If i delete the session_register() function, there will no error and at the same time , i can't login also when i key in the right details

So what is the problem? help me please? !!
thanks

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Login problem

Postby WiZARD » Mon Jul 19, 2004 3:03 am

as i see: headers already sent
what exactly at the c:\inetpub\wwwroot\opbs\member.php on line 20
meby better see what code above?

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Mon Jul 19, 2004 7:26 pm

DO NOT OUTPUT ANY HTML OR WHITESPACES before session_start() and all session related func.

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Postby kiwi » Tue Jul 20, 2004 7:07 am

the member.php code is this:

<style type="text/css">
<!--
body {
background-color: #E6E6E6;
}
-->
</style><?

// include function files for this application
require_once("bookmark_fns.php");
//session_start();

if ($username && $passwd)
// they have just tried logging in
{
if (login($username, $passwd))
{
// if they are in the database register the user id
$valid_user = $username;
session_register("valid_user");
main();
}
else
{
// unsuccessful login
do_html_header("Problem:");
echo "You could not be logged in.
You must be logged in to view this page.";
do_html_url("login.php", "Login");
do_html_footer();
exit;
}
}

do_html_header("Home");
check_valid_user();
// get the bookmarks this user has saved
if ($url_array = get_user_urls($valid_user));
display_user_urls($url_array);

// give menu of options
display_user_menu();

do_html_footer();

?>

the bold section is the line 20th. can some one help me to correct the error to prevent the error message mention previous section to show up,, thanks

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Tue Jul 20, 2004 8:06 am

ruturajv's advice was correct.

kiwi
New php-forum User
New php-forum User
Posts: 124
Joined: Sun Feb 29, 2004 6:26 am
Contact:

Postby kiwi » Tue Jul 20, 2004 8:20 am

how? i dont really understand, can u just correct the mistake and post it here so i can have a look, please, thanks

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Tue Jul 20, 2004 11:01 am

He said you can't have any output (that means text, HTML, echo statements, or includes that have the above) in the code before the session functions. So to fix your code, you have to make sure your session functions are in the code before any such output.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Tue Jul 20, 2004 8:01 pm

should be something like this

Code: Select all

<?php

// include function files for this application
require_once("bookmark_fns.php");
session_start();

if ($username && $passwd)
// they have just tried logging in
{
if (login($username, $passwd))
{
// if they are in the database register the user id
$valid_user = $username;
session_register("valid_user");
main();
}
else
{
?>
<style type="text/css">
<!--
body {
background-color: #E6E6E6;
}
-->
</style>
<?php
// unsuccessful login
do_html_header("Problem:");
echo "You could not be logged in.
You must be logged in to view this page.";
do_html_url("login.php", "Login");
do_html_footer();
exit;
}
}

do_html_header("Home");
check_valid_user();
// get the bookmarks this user has saved
if ($url_array = get_user_urls($valid_user));
display_user_urls($url_array);

// give menu of options
display_user_menu();

do_html_footer();

?>


Return to “PHP Scripts”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest