|
|
| Author |
Message |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: Session problem in user logon |
|
|
Hi,
I am facing some problems with session in user login .
My database table has 2 attributes name and password.
member_login.html:-
<html>
<body>
<form action="login.php" method='post'>
<input type="text" name="uid">
<input type="password" name="passwd">
</form>
</body>
</html>
login.php:-
<?php
session_start();
include 'connect.php';
$userid=$_POST['uid'];
$password=$_POST['passwd'];
$sql=mysql_query("select * from user where user_id='$userid' and passwd='$password'");
$login_check=mysql_num_rows($sql);
if($login_check==0)
echo " You have not uccessfillt loggedin ";
else
{
session_register('me');
$_SESSION['me']=$userid;
header("Location: login_success.php");
}
?>
login_success.php:-
<?php
session_start();
echo " .$_SESSION['me']. " ;
?>
Its giving me the following error:-
Warning: cannot modify header information: - headers already sent by(output startted at /var/www/html/login.php:6) in /var/www/html/login.php on line 19 |
|
Thu Jul 15, 04 9:51 pm
 |
|
 |
quantum Site Admin


Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
|
Post subject: |
|
|
Most possible solutions:
1. Make sure there is no extra space, line break, entry before <? or after ?> in all the php files.
2. There are certain PHP functions that PHP requires to be output before anything else, such as starting a session or using the header function. When it says ERROR: Headers already sent it is simply telling you that you output HTML before you sent the headers.
You did not post what is in connect.php but make sure that there is no html or text in there. Also try to move include 'connect.php'; after session commands.
3. Try putting ob_start() beginning of ur code and ob_end_flush() at the end of ur code. (i read about it somewhere but not sure).
4. If all else fails just shut the error up with @ sign at line 6 or wherever the error is showing. This is not fatal error, just a warning and your code will do what it was meant to do. _________________
Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
|
|
Thu Jul 15, 04 11:14 pm
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
Its now giving me another error at login_success.php:-
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /var/www/html/login_success.php on line 3 |
|
Fri Jul 16, 04 1:27 am
 |
|
 |
quantum Site Admin


Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
|
|
Fri Jul 16, 04 2:54 am
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
As i am new to session part I gave it a print to see it user_id is really registered.
But it shows me nothing in login_success.php where is should be printing the user_id value from databse which I registered through session. |
|
Fri Jul 16, 04 6:24 am
 |
|
 |
quantum Site Admin


Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
|
|
Fri Jul 16, 04 6:28 am
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
Tried but shows nothing |
|
Fri Jul 16, 04 7:50 am
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
done , Thankz a lot for helping me out all of u. |
|
Fri Jul 16, 04 8:33 am
 |
|
 |
quantum Site Admin


Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
|
|
Fri Jul 16, 04 11:11 am
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
The problem was in the konqueror browser of linux I was using.
The cookie option of the browser wasn't set enable so it was rejecting.
I just checked the accept all cookies by default option from the settings and it just worked out. |
|
Fri Jul 16, 04 12:57 pm
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
need help again.
As I was able to successfully login and can use session to keep track of user, now the problem is with logout.
I wrote a logout.php page and when the user clicks, it just unregister the session variable using session_unregister('userid').here is logout.php code:-
[PHP]
<?php
session_start();
if(!isset($_SESSION[userid]))
echo " You are Already logged OUT";
else
echo 'you are logged out';
session_unset();
session_destroy();
session_unregister('userid');
echo '<a href="member_list.php">Member</a>';
?>
[/PHP]
Currently working with 4 files for testing this :-
login.php = for user login
login_success.php = after successful login it shows a welcome msg and redirects to member_list.php page.
member_list.php = to view the member list from database.
logout.php= for logout
Now when I first submit the login.php page it shows me all the memeber list using member_list.php, no problem in that. But when I logout using logout.php page I put a link to member_list.php page again to see if its showing me the list which it shouldn't if i don't login.
Its not showing the list alright but giving those warnings again.
What to do abt it?? |
|
Sat Jul 17, 04 11:49 am
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
need help again.
As I was able to successfully login and can use session to keep track of user, now the problem is with logout.
I wrote a logout.php page and when the user clicks, it just unregister the session variable using session_unregister('userid').here is logout.php code:-
<?php
session_start();
if(!isset($_SESSION[userid]))
echo " You are Already logged OUT";
else
echo 'you are logged out';
session_unset();
session_destroy();
session_unregister('userid');
echo '<a href="member_list.php">Member</a>';
?>
The php part of member_list.php code like:-
<?php
session_start();
if(!isset($_SESSION[userid])) echo "U are not authorized to access this page";
else
echo " Welcome , to Member list Area :-<br> ";
if(isset($_SESSION[userid]))
// Connect to database and do some query.
?>
Currently working with 4 files for testing this :-
login.php = for user login
login_success.php = after successful login it shows a welcome msg and redirects to member_list.php page.
member_list.php = to view the member list from database.
logout.php= for logout
Now when I first submit the login.php page it shows me all the memeber list using member_list.php, no problem in that. But when I logout using logout.php page I put a link to member_list.php page again to see if its showing me the list which it shouldn't if i don't login.
Its not showing the list alright but giving those warnings again.
What to do abt it?? |
|
Sat Jul 17, 04 11:50 am
 |
|
 |
quantum Site Admin


Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
|
Post subject: PHP Header already sent error? |
|
|
Hi Tanveer,
What are the errors now? If these are the same errors then the solution is the same. Make sure there is no html output before session calls. Try moving all the echo parts at the bottom of the codes. Instead, assign a value for a variable for each if statement.
Let me know what happens. _________________
Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
|
|
Sun Jul 18, 04 5:35 am
 |
|
 |
tanveer User


Joined: 21 Jun 2004 Posts: 85
Location: Dhaka,Bangladesh
|
Post subject: |
|
|
sorry for my late response. Ii was out of town.
Now, I have no problem in login or logout and I was doing it just for learning session. Now I want to include in a project of mine where there is a total of 56 html and PHP pages. Now, suppose the main page in index.html and there i put a link of login.After user logged in then I have to show user logout link. but after logging in if user went to any html page how would I show him the logout link bcz i cant get the session variable there.
What u suggeest do I convert all my html pages in PHP page??
Hope I made myself clear. |
|
Tue Jul 20, 04 5:11 am
 |
|
 |
quantum Site Admin


Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
|
Post subject: |
|
|
Hi Tanveer,
No problem. Hope you had fun. Now we would really appreciate it if you included with your messages the exact solutions that you used to the problems you posted. So that we know what really went on. Php is a very useful language to learn and I congratulate you on your decision to learn it.
If you want to process or show the log in/log out link dynamically it has to use php and thus .php extension. That'd be much efficient than anything else. Or you can show the logout link on every page no matter if the user is logged in or logged out. When clicked, logout link will take him to a logout.php page where you can have the sessions terminated. But that's rather awkward. Just change the file extensions. _________________
Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
|
|
Tue Jul 20, 04 6:11 am
 |
|
 |
|