PDA

View Full Version : حرفه ای: در مورد session .. لطفا هرکس در این رابطه حرفه ای پاسخ بده ممنون میشم



iranibahar
دوشنبه 13 خرداد 1392, 23:12 عصر
<form method="post" action="do_session.php" >
<label id="label" > نام کاربری : </label>
<input height="7px" size="40" name="username" type="text" /><br /><br />
<label id="label" > پسورد : </label>
<input height="7px" size="40" name="password" type="password" /><br /><br />
<p><input type="submit" name="submit" value=" log in " /></p>
<input type="hidden" name="destination" value="<?php print $_server['request_url']; ?>">
</form>



ایراد این تیکه کد چیه ؟



<?php
session_start();
$passwords=array( "chris" => "letmein" ,
"damon" => "thisisme" , "shelley" => "mypassword" , "vanessa" => "opensesame" ,
);
if (!$_post['username'] or !$_post['password']) {
echo " you must enter your username and password ";
exit;
}
$salt=substr($passwords[$_post['username']],0,2);
if (crypt($_post['password'],$salt) == $passwords[$_post['username']]) {
echo " login successfull ";
//header("location : $_post[destination]");
$_session['auth_username'] = $_post['username'];
}
else {
echo " login incorrect ";

}
?>



این خطا رو میده


Warning: session_start() [function.session-start (http://localhost/function.session-start)]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\do_session.php:2) in C:\xampp\htdocs\do_session.php on line 3

Warning: session_start() [function.session-start (http://localhost/function.session-start)]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\do_session.php:2) in C:\xampp\htdocs\do_session.php on line 3
you must enter your username and password

105098

dousti_design
دوشنبه 13 خرداد 1392, 23:18 عصر
به احتمال زیاد فایل do_session.php حاوی BOM هستش. فایل رو با notepad++ باز کنید و از منوی Format گزینه utf8 without BOM رو انتخاب و فایل رو Save As کنید.

arefd2010
سه شنبه 14 خرداد 1392, 01:13 صبح
سلام
وقتی دارین از session استفاده میکنید نباید قبل ارsession_start() چیزی رو چاپ کنید که شما در خط :




<input type="hidden" name="destination" value="<?php print $_server['request_url']; ?>">


از دستور print استفاده کردید....