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

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

kfir91 20-07-08 18:38

שגיאה עם קוקיס ו headers
 
זה השגיאה :
קוד:

Warning: Cannot modify header information - headers already sent by (output started
זה הקוד :
קוד:

<html dir="rtl">
<head>
        <title>דף ראשי</title>
        <? include "config.php"; ?>
</head>
<body>

<?
$hour = time() + 3600;
$username = $_COOKIE['user'];
$password = $_COOKIE['pass'];

if(!isset($_COOKIE['user']))
    {
    echo "אתה אינך מחובר :: <a href=\"?act=loginform\">התחברות</a><br />";
    }
else
    echo "ברוך הבא $username :: <a href=\"?act=logout\">התנתק</a><br />";

$act = $_GET['act']; // הגדרת משתנה ראשי

if ($act == "logincheck") // בדיקת התחברות
{
// הכנסת פרטי הטופס למשתנים
$user = $_POST['User'];
$pass = $_POST['Pass'];

// בדיקת טופס

echo "
        <table class=\"loginchecktable\">
        <tr><td valign=\"top\" dir=\"rtl\" class=\"login_check_td_table\">";

        if ($pass == "")
        {
          echo "סיסמא לא הוזנה";
          echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">";
        }
        else if ($user == "")
        {
          echo "שם משתמש לא הוזן";
          echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">";
        }
        else
        {
        $s = mysql_query("SELECT * FROM members WHERE username='$user' && password='$pass'") or die(mysql_error());
        $checkform = mysql_num_rows($s);

                if ($checkform == "0")
                {
                echo "אחד מהפרטים אינו נכון";
                echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">";
                }
                else
                {
                  echo "התחברת בהצלחה";
                  setcookie(user, $user, $hour);
                  setcookie(pass, $pass, $hour);
                  echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">";
                }
        }

echo "</td></tr>";
echo "</table>";
}

else if ($act =="loginform") // טופס התחברות
{
if(!isset($_COOKIE['user']))
{
echo <<<LOGINFORM

<form action="?act=logincheck" method="post">
<table class="logintable">

        <tr><td valign="top" dir="rtl" class="logintdtable">שם משתמש: </td>
        <td valign="top" dir="rtl" class="logintdtable"><input type="text" name="User"></td>
        </tr>
        <tr><td valign="top" dir="rtl" class="logintdtable">סיסמא:  </td>
        <td valign="top" dir="rtl" class="logintdtable"><input type="password" name="Pass"></td>
        </tr>
        <tr><td valign="top" dir="rtl" class="logintdtable"></td>
        <td valign="top" dir="rtl" class="logintdtable"><input type="reset" value="נקה"><input type="submit" value="התחבר"></td>
        </tr>
</table>
</form> 

LOGINFORM;
}
else
  {
  echo "אתה מחובר למערכת";
  echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">";
  }
}

else if($act == "logout")
{
  $past = time() - 100;
  setcookie(user, gone, $past);
  setcookie(pass, gone, $past);
  echo "התנתקת בהצלחה";
  echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">";
}

?>

</body>
</html>

הבעיה היא בשורות :
קוד:

                  setcookie(user, $user, $hour);
                  setcookie(pass, $pass, $hour);


amirs_5 20-07-08 18:43

זה בגלל ששלחת HTML לפני יצירת העוגיה..
אתה צריך לרשום בראש העמוד:
PHP קוד:

ob_start(); 

ובסופו עם
PHP קוד:

ob_end_flush(); 

מקווה שעזרתי..

kfir91 20-07-08 18:46

ניסי י מקודם לעשות את זה עם ob_end_clean אבל משום מה הוא לא יצר את הקוקיס...
עריכה : הנה גם עכשיו ברגע שאני עושה מה שאמרת הוא באמת לא מציג תשגיאה
אבל הוא לא מבצע ת setcookies יענו הוא מציג אתה לא מחובר לפי התנאי בקוד. שהוא אמור להציג "ברוך הבא" כי התחברתי

amirs_5 20-07-08 19:23

העוגייה בכל מקרה אמורה להיווצר, תנסה להדפיס אותה כדי לאמת זאת, ותראה מה היא מציגה לך.

BlueNosE 20-07-08 19:25

לפי מה שאני זוכר, אחרי SETCOOKIE לא מתבצע אתחול איבר במערך $_COOKIES, אתה צריך לבדוק בדרך אחרת אם העוגיה קיימת או לרענן את הדף.
אני לא בטוח ב-100&#37; שזה נכון

kfir91 20-07-08 20:50

אני מרענן את הדף זה לא עובד..
והעוגיה מחזירה ריק... למה?

Elad-A 20-07-08 20:54

תעשה print_r($_COOKIE); בדף ותרשום מה הפלט.

kfir91 20-07-08 20:59

זה רושם את זה :
קוד:

Array ( [__utma] => 3769970.1222316683.1216412329.1216412329.1216412329.1 [__utmz] => 3769970.1216412329.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none) )

WCMS 21-07-08 12:21

ציטוט:

נכתב במקור על ידי kfir91 (פרסם 652183)
זה רושם את זה :
קוד:

Array ( [__utma] => 3769970.1222316683.1216412329.1216412329.1216412329.1 [__utmz] => 3769970.1216412329.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none) )

הקוד הזה אומר שיש באתר שלך מודעות של גוגל |winky|
ואין פה את העוגייה שלך.

PHP קוד:

setcookie(user$user$hour);
setcookie(pass$pass$hour); 

לא עושים ככה
עושים
PHP קוד:

setcookie("user"$user$hour);
setcookie("pass"$pass$hour); 

מקווה שזה יעבוד!
בברכה, יורי.

kfir91 21-07-08 15:12

עשיתי ככה לפני שאמרת.. זה לא עובד

Erez | TrustMedia.co.il 21-07-08 18:05

תסדר את הקוד כך שהעוגייה תהיה בראש העמוד(כל התנאי שלה)
כתבתי לך תגובה כבר בפורום אחר

kfir91 21-07-08 21:48

ואני אמרתי לך שהתנאי חייב להתמקם שם והכל חייב להתמקם כמו שזה .
זה אמור ליצור תעוגיה מה זה משנה איפה היא

Daniel 21-07-08 21:54

אז תלמד לעבוד עם מערכת טמפלייטים. ולשמור את כל הoutput במשתנה.

kfir91 21-07-08 21:59

מה זה מערכת טמפלייטים
מה הקשר מערכת טמפלייטים בכלל אני רק צריך שהקוקי הזה יווצר

Daniel 21-07-08 22:08

באיזה רמה אתה מעוניין לתכנת?
ברמה נמוכה? תוסיף ob_start
ברמה בינונית? תשמור את הכל במשתנה ורק בסוף תציג אותו.
ברמה גבוהה באמת? תעבוד עם מערכת טמפלייטים.

kfir91 21-07-08 22:18

מה אתה לא מבין שהוספתי ob_start אתה לא קורא את הדיון ?
יש בעיה חדשה שהוא לא יוצר את הקוקי עכשיו הוא כבר לא מראה שגיאה רק לא יוצר תקוקי

Daniel 22-07-08 00:44

תאמין לי שלא הרג אף אחד טיפה, טיפה, טיפה לנסות.
PHP קוד:

<?php
error_reporting
(E_ALL);
include 
"config.php";
$tp = <<<EOF
<html dir="rtl">
<head>
    <title>דף ראשי</title>
</head>
<body>
EOF;
$hour time() + 3600;
$username $_COOKIE['user'];
$password $_COOKIE['pass'];

if (!isset(
$_COOKIE['user'])) {
    
$tp .= "אתה אינך מחובר :: <a href=\"?act=loginform\">התחברות</a><br />";
} else
    
$tp .= "ברוך הבא $username :: <a href=\"?act=logout\">התנתק</a><br />";

$act = isset($_GET['act']) ? $act $_GET['act'] : $act "loginform"// הגדרת משתנה ראשי

if ($act == "logincheck") { // בדיקת התחברות
    // הכנסת פרטי הטופס למשתנים
    
$user $_POST['User'];
    
$pass $_POST['Pass'];
    
// בדיקת טופס
    
$tp .= "
    <table class=\"loginchecktable\">
    <tr><td valign=\"top\" dir=\"rtl\" class=\"login_check_td_table\">"
;

    if (
$pass == "") {
        
$tp .= "סיסמא לא הוזנה
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">"
;
    } else if (
$user == "") {
        
$tp .= "שם משתמש לא הוזן
       <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">"
;
    } else {
        
$s mysql_query("SELECT * FROM members WHERE username='$user' && password='$pass'") or die(mysql_error());
        
$checkform mysql_num_rows($s);

        if (
$checkform == "0") {
            
$tp .= "אחד מהפרטים אינו נכון
        <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">"
;
        } else {
            
$tp .= "התחברת בהצלחה<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">";
            
setcookie('user'$user$hour);
            
setcookie('pass'$pass$hour);
        }
    }

    
$tp .= "</td></tr>
</table>"
;
} else if (
$act == "loginform") { // טופס התחברות
    
if (!isset($_COOKIE['user'])) {
        
$tp .= <<<LOGINFORM

<form action="?act=logincheck" method="post">
<table class="logintable">

    <tr><td valign="top" dir="rtl" class="logintdtable">שם משתמש: </td>
    <td valign="top" dir="rtl" class="logintdtable"><input type="text" name="User"></td>
    </tr>
    <tr><td valign="top" dir="rtl" class="logintdtable">סיסמא:  </td>
    <td valign="top" dir="rtl" class="logintdtable"><input type="password" name="Pass"></td>
    </tr>
    <tr><td valign="top" dir="rtl" class="logintdtable"></td>
    <td valign="top" dir="rtl" class="logintdtable"><input type="reset" value="נקה"><input type="submit" value="התחבר"></td>
    </tr>
</table>
</form>

LOGINFORM;
    } else {
        
$tp .= "אתה מחובר למערכת
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">"
;
    }
} else if (
$act == "logout") {
    
$past time() - 100;
    
setcookie('user''I dont know PHP'$past);
    
setcookie('pass''I dont know PHP'$past);
    
$tp .= "התנתקת בהצלחה
        <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">"
;
}
$tp .= "</body></html>";
echo 
$tp;

?>


kfir91 22-07-08 05:44

Notice: Undefined index: user in /home/netanya/domains/sportn.co.il/public_html/login/index.php on line 12

Notice: Undefined index: pass in /home/netanya/domains/sportn.co.il/public_html/login/index.php on line 13

Daniel 22-07-08 16:02

PHP קוד:

<?php

include "config.php";
$tp = <<<EOF
<html dir="rtl">
<head>
    <title>דף ראשי</title>
</head>
<body>
EOF;
$hour time() + 3600;
$username $_COOKIE['user'];
$password $_COOKIE['pass'];

if (!isset(
$_COOKIE['user'])) {
    
$tp .= "אתה אינך מחובר :: <a href=\"?act=loginform\">התחברות</a><br />";
} else
    
$tp .= "ברוך הבא $username :: <a href=\"?act=logout\">התנתק</a><br />";

$act = isset($_GET['act']) ? $act $_GET['act'] : $act "loginform"// הגדרת משתנה ראשי

if ($act == "logincheck") { // בדיקת התחברות
    // הכנסת פרטי הטופס למשתנים
    
$user $_POST['User'];
    
$pass $_POST['Pass'];
    
// בדיקת טופס
    
$tp .= "
    <table class=\"loginchecktable\">
    <tr><td valign=\"top\" dir=\"rtl\" class=\"login_check_td_table\">"
;

    if (
$pass == "") {
        
$tp .= "סיסמא לא הוזנה
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">"
;
    } else if (
$user == "") {
        
$tp .= "שם משתמש לא הוזן
       <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">"
;
    } else {
        
$s mysql_query("SELECT * FROM members WHERE username='$user' && password='$pass'") or die(mysql_error());
        
$checkform mysql_num_rows($s);

        if (
$checkform == "0") {
            
$tp .= "אחד מהפרטים אינו נכון
        <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=?act=loginform\">"
;
        } else {
            
$tp .= "התחברת בהצלחה<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">";
            
setcookie('user'$user$hour);
            
setcookie('pass'$pass$hour);
        }
    }

    
$tp .= "</td></tr>
</table>"
;
} else if (
$act == "loginform") { // טופס התחברות
    
if (!isset($_COOKIE['user'])) {
        
$tp .= <<<LOGINFORM

<form action="?act=logincheck" method="post">
<table class="logintable">

    <tr><td valign="top" dir="rtl" class="logintdtable">שם משתמש: </td>
    <td valign="top" dir="rtl" class="logintdtable"><input type="text" name="User"></td>
    </tr>
    <tr><td valign="top" dir="rtl" class="logintdtable">סיסמא:  </td>
    <td valign="top" dir="rtl" class="logintdtable"><input type="password" name="Pass"></td>
    </tr>
    <tr><td valign="top" dir="rtl" class="logintdtable"></td>
    <td valign="top" dir="rtl" class="logintdtable"><input type="reset" value="נקה"><input type="submit" value="התחבר"></td>
    </tr>
</table>
</form>

LOGINFORM;
    } else {
        
$tp .= "אתה מחובר למערכת
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">"
;
    }
} else if (
$act == "logout") {
    
$past time() - 100;
    
setcookie('user''I dont know PHP'$past);
    
setcookie('pass''I dont know PHP'$past);
    
$tp .= "התנתקת בהצלחה
        <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL=index.php\">"
;
}
$tp .= "</body></html>";
echo 
$tp;

?>



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

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