friends
i,m facing a strange problem with session
1- i established my first php website and it is working good on local host and according to the tutorials i had to learn php which i followed them well i used to include this code at the head of each page i need to have a session with it
but when checking my website (online ) not from local host
i get this message
(
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ansaferc/public_html/mypage.php:3) in /home/ansaferc/public_html/mypage.php on line 4
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ansaferc/public_html/mypage.php:3) in /home/ansaferc/public_html/mypage.php on line 4
)
this is the code i have in the index.php page which allow the user to loging and creat the session for this user
(
<!--- login form and php process--->
<?php
/*getting login variables */
$username = strip_tags(@$_POST['username']);
$userpass = strip_tags(@$_POST['password']);
$submit =@$_POST['usersubmit'];
if ($submit){
/* Data base connection */
include ("config.php");
/* check for username and password*/
if (!$username==""){
if (!$userpass==""){
$userpass = md5(strip_tags(@$_POST['password']));
$query = mysql_query("SELECT * from commercial_members WHERE username='$username'") or die("couldn,t connect");
$num = mysql_num_rows($query);
if ($num!=0){
while($row = mysql_fetch_assoc($query)){
$dbusername=$row['username'];
$dbpassword=$row['userpass'];
}
if ($userpass==$dbpassword){
@$_SESSION['username']=$username;
}else {echo " wrong password ";}
}else {echo " Unknown user name ";}
}else {echo " you must enter password ";}
}else {echo " you must enter user name";}
}
echo" ";
?>
)
so when i login in the index.php page i can see that the session is established but if i (either refresh the page or moved to any other page ) i don,t see that session and i see that message that you,re not logged in plz login or register with us and if i used the back button to go back to the previous page i see thate session again
i tried many time with this problem but it did not work although it is going well on localhost
need your assistance