הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   בעיה בעוגיה (cookie) (https://hosts.co.il/forums/showthread.php?t=64918)

lior19901 07-07-08 18:06

בעיה בעוגיה (cookie)
 
למה זה לא יוצר לי את ה cookie ברגע שמסמנים את ה checkbox הוא צריך ליוצר לי את ה cookie
הוא מעביר אותי לדף שהגדרתי לו ברגע שמסמנים את checkbox אבל זה לא יוצר לי cookie

PHP קוד:

function die_form($err) {
    print 
"<caption align=\"center\">התחברות למערכת</caption>";
    if(!empty(
$err)) {
        print 
"    <tr>
        <td align=\"right\" width=\"100%\" colspan=\"2\">"
.$err."</td></tr>";
    }
    
$agree mysql_real_escape_string($_POST['agree']);
    print 
"<form action=\"".$PHP_SELF."\" method=\"POST\">
    <tr>
        <td align=\"right\" width=\"30%\" height=\"40%\"><span class=\"text007\">שם משתמש:</span></td>
        <td align=\"right\" width=\"70%\" height=\"40%\"><input type=\"text\" name=\"username\" witdh=\"100%\" height=\"100%\""
; if(isset($_COOKIE["username"])) { print " value=\"".$_COOKIE["username"]."\""; } print ">
                                <label for=\"checkbox\">
                                <input type=\"checkbox\" id=\"checkbox\" name=\"agree\" value=\"CHECKED\" $agree>
                                 התחבר אוטומטית בכניסה הבאה?
                                </label>
                                </td>
    </tr>
    <tr>
        <td align=\"right\" width=\"30%\" height=\"40%\" class=\"text007\">סיסמא:</td>
        <td align=\"right\" width=\"70%\" height=\"40%\"><input type=\"password\" name=\"password\" witdh=\"100%\" height=\"100%\"></td>
    </tr>
    <tr>
        <td align=\"center\" width=\"100%\" height=\"25%\" colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"התחבר\" style=\"border:1px solid; background-color:#ffffff;\"><input type=\"reset\" value=\"נקה\" style=\"border:1px solid; background-color:#ffffff;\"></td>
    </tr>
    </form>"
;

}
if(isset(
$_POST['submit'])) {
    
$con_pass md5($_POST['password']);
    
$result mysql_query("Select * from `users` WHERE `username`='".$_POST['username']."' AND `password`='".$con_pass."'",$link);
    
$rows mysql_num_rows($result);
    if(
$rows == 0) {
        
die_form("שם משתמש או סיסמא שגויים");
    }
    else {
    
$a_row mysql_fetch_object($result);
    
$_SESSION["username"] = $a_row->username;
    
$_SESSION["password"] = $a_row->password;
    
$agree mysql_real_escape_string($_POST['agree']);
                if (
$agree == CHECKED) {
                
setcookie("cookie","Lior:123456",time()+3600*24*7);
    print 
"<script>location.href='index.php?profile=edit_profile';</script>";
    }
    print 
"<script>location.href='index.php';</script>";
    }


מה הבעיה?

Daniel 07-07-08 18:31

מהההההההההה לאאאאאאאאאאא עובד..

מה לא עובד.

למה כשאני שותה תה זה לא עובד לי? למה?

-----------------------------------------------------------

השגיאה היא בדיוק, ללא עוררין, בשורה הזאת
[php] if ($agree == CHECKED) { [/php

והיא לא זה:

PHP קוד:

                if ($agree == 

והיא לא זה:

PHP קוד:

) { 

...

lior19901 07-07-08 19:20

זה מעביר אותי לדף
index.php?profile=edit_profile
אז זה לא הבעיה
עם זה לא היה טוב לא היה מעביר אותי לדף הזה

BlueNosE 07-07-08 19:22

מה שדניאל מנסה לומר, זה שאתה מנסה להשוות את $agreed לSTRING, וזו לא הדרך לבדוק.

ד"א, אם היית שם ERROR_REPORTING, היית רואה שגיאה שאומרת שאתה צריך לשים גרשיים ושהשפה מתעלמת.

lior19901 07-07-08 19:44

אז מה לעשות כדי שיוצר לי תעוגיה?

AlmogBaku 07-07-08 21:09

לא צריך להיות גאון
PHP קוד:

if($_POST['remember'] == "on"


lior19901 07-07-08 21:17

כן עשיתי אבל זה לא עוזר לי זה לא יוצר לי את ה cookie

AlmogBaku 07-07-08 21:18

אז תן לנו את הקוד אחרי השינויים..

lior19901 07-07-08 21:23

PHP קוד:

<?php 

require('db.php');


echo 
"
<html>
<head>
<title>שלום</title>
<style type='text/css'>
<!--
body { background-color: #000000; }
body,td,th {
    font-family: Tahoma, Helvetica, sans-serif;
    font-size: 14px; color:#FFFFFF;
              border: 1px;
}
-->
</style>
</head>
<body dir='rtl'>
<table align='right' border='0' dir='rtl'>"
;

function 
die_form($err) {
    print 
"<caption align=\"center\">התחברות למערכת</caption>";
    if(!empty(
$err)) {
        print 
"    <tr>
        <td align=\"right\" width=\"100%\" colspan=\"2\">"
.$err."</td></tr>";
    }
    
$agree mysql_real_escape_string($_POST['agree']);
    print 
"<form action=\"".$PHP_SELF."\" method=\"POST\">
    <tr>
        <td align=\"right\" width=\"30%\" height=\"40%\"><span class=\"text007\">שם משתמש:</span></td>
        <td align=\"right\" width=\"70%\" height=\"40%\"><input type=\"text\" name=\"username\" witdh=\"100%\" height=\"100%\""
; if(isset($_COOKIE["username"])) { print " value=\"".$_COOKIE["username"]."\""; } print ">
                                <label for=\"checkbox\">
                                <input type=\"checkbox\" id=\"checkbox\" name=\"agree\" value=\"CHECKED\" $agree>
                                 התחבר אוטומטית בכניסה הבאה?
                                </label>
                                </td>
    </tr>
    <tr>
        <td align=\"right\" width=\"30%\" height=\"40%\" class=\"text007\">סיסמא:</td>
        <td align=\"right\" width=\"70%\" height=\"40%\"><input type=\"password\" name=\"password\" witdh=\"100%\" height=\"100%\"></td>
    </tr>
    <tr>
        <td align=\"center\" width=\"100%\" height=\"25%\" colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"התחבר\" style=\"border:1px solid; background-color:#ffffff;\"><input type=\"reset\" value=\"נקה\" style=\"border:1px solid; background-color:#ffffff;\"></td>
    </tr>
    </form>"
;

}
if(isset(
$_POST['submit'])) {
    
$con_pass md5($_POST['password']);
    
$result mysql_query("Select * from `users` WHERE `username`='".$_POST['username']."' AND `password`='".$con_pass."'",$link);
    
$rows mysql_num_rows($result);
    if(
$rows == 0) {
        
die_form("שם משתמש או סיסמא שגויים");
    }
    else {
    
$a_row mysql_fetch_object($result);
    
$_SESSION["username"] = $a_row->username;
    
$_SESSION["password"] = $a_row->password;

                if(
$_POST['agree'] == "CHECKED") {
                
setcookie("user","Lior:123",time()+3600*24*7);
                echo 
"מחובר אוטומטית";
    }
                echo 
"<br>מחובר רגיל";
    }
}
else {
die_form("");
}
echo 
"
</table>
</body>
</html>"
;
?>

שגיאה שאני מקבל שאני מסמן את ה-checkbox:

קוד:

Warning: Cannot modify header information - headers already sent by (output started at /home/lior19901/domains/djelmix.www3.co.il/public_html/site/11.php:22) in /home/lior19901/domains/djelmix.www3.co.il/public_html/site/11.php on line 64

BlueNosE 07-07-08 22:55

שים אחרי הPHP
ob_start();

אפילו אין לי כוח להסביר לך למה.


כל הזמנים הם GMT +2. הזמן כעת הוא 06:02.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ