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

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

dor77 01-03-10 21:18

בעייה בהצבת עוגיות..הדרים נשלחו..
 
שלום.
בניתי טופס התחברות.
הרעיון הוא כזה:

אם הכפתור נלחץ - המערכת תבדוק אם הפרטים נכונים, אם כן תחבר את המשתמש, אם לא (else) מציג לו את הטופס עם שגיאה.
אם הכפתור לא נשלח - מציג לו את הטופס בלבד.

כשאני מצליח להתחבר..אני מקבל שגיאה:
Cannot modify header information - headers already sent by
אני מקבל פעמיים, השורות שמצויינות הן השורות של הצבת העוגיות.


זה הקוד המלא:

PHP קוד:



<?php

mysql_connect
("localhost""root""");
mysql_select_db("phpmyadmin"); 

$user_name mysql_real_escape_string(htmlspecialchars($_POST['user_name']));
$password mysql_real_escape_string(htmlspecialchars(md5($_POST['password'])));

$query mysql_query("SELECT * FROM users WHERE user_name='$user_name'"); 
$row=mysql_fetch_array($query);

$row_password=$row['password'];
$row_user_name=$row['user_name'];
$password_cookie=$row['password'];
$user_name_cookie=$row['user_name'];

if (isset(
$_POST['submit']))
{
if (
$row_password==$password && $row_user_name==$user_name)
{
    
setcookie("username"$user_nametime()+60000);
    
setcookie("id"$id_cookietime()+60000);
    echo 
'<meta http-equiv="refresh" content="0;url=index.php" />'
}
  else
{
        echo 
'
    
        <div id="top_menu">
        <span class="menu_class">
        <a href="sign_in.php">Login</a>&nbsp;&nbsp;
        <a href="sign_up.php">Register</a>
        </span>
        </div>
        
        <h1>Login to your account...</h1> 
        
          <div id="register_message"><p class="failed">Login Fail!</p>
        <span class="failed">Please check your deatiles and try again.</span></div> 
        
        <div id="form">
        <form action="" method="POST">
        <table id="registertable" cellpadding="10" border="0">
        <tr>
            <td align="left">
                <span class="field">Username:</span>
            </td>
            <td align="left">
                    <input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
            </td>
        </tr>
        <tr>
            <td align="left">
                <span class="field">Password:</span>
            </td>
            <td align="left">
                <input type="Password" name="password" id="password" dir="ltr"  value="" style="width:200px;" maxlength="15">
            </td>      
        <tr>
            <td align="right"></td>
            <td align="center">
                <label>&nbsp; </label><input type="submit" name="submit" value="" id="submit" />
            </td> 
        </tr>
        </table>
        </form>
        </div>
    
        <div id="copyrights">
        © All rights reserved.
        </div>
}
        '
;
}

}
else
{
        echo 
'
    
        <div id="top_menu">
        <span class="menu_class">
        <a href="sign_in.php">Login</a>&nbsp;&nbsp;
        <a href="sign_up.php">Register</a>
        </span>
        </div>
        
        <h1>Login to your account...</h1> 
        
        <div id="form">
        <form action="" method="POST">
        <table id="registertable" cellpadding="10" border="0">
        <tr>
            <td align="left">
                <span class="field">Username:</span>
            </td>
            <td align="left">
                    <input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
            </td>
        </tr>
        <tr>
            <td align="left">
                <span class="field">Password:</span>
            </td>
            <td align="left">
                <input type="Password" name="password" id="password" dir="ltr"  value="" style="width:200px;" maxlength="15">
            </td>      
        <tr>
            <td align="right"></td>
            <td align="center">
                <label>&nbsp; </label><input type="submit" name="submit" value="" id="submit" />
            </td> 
        </tr>
        </table>
        </form>
        </div>
    
        <div id="copyrights">
        © All rights reserved.
        </div>
        '
;
}


?>

לא כתבתי שום דבר לפני כן, הדף ריק לגמרי..מה נחשב "header"? אולי הלולאה שם?

תודה רבה לכם :)

Daniel 01-03-10 21:42

יש לך 2 אנטרים בראש הדף.

dor77 01-03-10 21:51

מחקתי אותם..עדיין.
אנטר יכול לעשות דבר כזה? חח
בכל אופן לא עזר..אתה רואה משהו אחר אולי?

טנקס (:

Daniel 01-03-10 22:27

כל טקסט. שלח מחדש את מה שעכשיו כתוב.

באיזה קידוד אתה שומר את זה?

dor77 01-03-10 22:43

כתוב בדיוק אותה שגיאה.
הקידוד הוא utf-8.

Daniel 01-03-10 22:46

1. את הקוד. שלח את הקוד בדיוק כמו שמופיע לך בקובץ.
2. שמור כ-UTF WITHOUT BOM.

dor77 01-03-10 22:58

זה הקוד:
PHP קוד:

<?php
mysql_connect
("localhost""root""");
mysql_select_db("phpmyadmin"); 
$user_name mysql_real_escape_string(htmlspecialchars($_POST['user_name']));
$password mysql_real_escape_string(htmlspecialchars(md5($_POST['password'])));
$query mysql_query("SELECT * FROM users WHERE user_name='$user_name'"); 
$row=mysql_fetch_array($query);
$row_password=$row['password'];
$row_user_name=$row['user_name'];
$password_cookie=$row['password'];
$user_name_cookie=$row['user_name'];
if (isset(
$_POST['submit']))
{
if (
$row_password==$password && $row_user_name==$user_name)
{
    
setcookie("username"$user_nametime()+60000);
    
setcookie("id"$id_cookietime()+60000);
    echo 
'<meta http-equiv="refresh" content="10;url=index.php" />'
}
  else
{
        echo 
'
    
        <div id="top_menu">
        <span class="menu_class">
        <a href="sign_in.php">Login</a>&nbsp;&nbsp;
        <a href="sign_up.php">Register</a>
        </span>
        </div>
        
        <h1>Login to your account...</h1> 
        
          <div id="register_message"><p class="failed">Login Fail!</p>
        <span class="failed">Please check your deatiles and try again.</span></div> 
        
        <div id="form">
        <form action="" method="POST">
        <table id="registertable" cellpadding="10" border="0">
        <tr>
            <td align="left">
                <span class="field">Username:</span>
            </td>
            <td align="left">
                    <input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
            </td>
        </tr>
        <tr>
            <td align="left">
                <span class="field">Password:</span>
            </td>
            <td align="left">
                <input type="Password" name="password" id="password" dir="ltr"  value="" style="width:200px;" maxlength="15">
            </td>      
        <tr>
            <td align="right"></td>
            <td align="center">
                <label>&nbsp; </label><input type="submit" name="submit" value="" id="submit" />
            </td> 
        </tr>
        </table>
        </form>
        </div>
    
        <div id="copyrights">
        © All rights reserved.
        </div>
}
        '
;
}

}
else
{
        echo 
'
    
        <div id="top_menu">
        <span class="menu_class">
        <a href="sign_in.php">Login</a>&nbsp;&nbsp;
        <a href="sign_up.php">Register</a>
        </span>
        </div>
        
        <h1>Login to your account...</h1> 
        
        <div id="form">
        <form action="" method="POST">
        <table id="registertable" cellpadding="10" border="0">
        <tr>
            <td align="left">
                <span class="field">Username:</span>
            </td>
            <td align="left">
                    <input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
            </td>
        </tr>
        <tr>
            <td align="left">
                <span class="field">Password:</span>
            </td>
            <td align="left">
                <input type="Password" name="password" id="password" dir="ltr"  value="" style="width:200px;" maxlength="15">
            </td>      
        <tr>
            <td align="right"></td>
            <td align="center">
                <label>&nbsp; </label><input type="submit" name="submit" value="" id="submit" />
            </td> 
        </tr>
        </table>
        </form>
        </div>
    
        <div id="copyrights">
        © All rights reserved.
        </div>
        '
;
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Your Private Homepage</title>
    <meta  http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
body {
    background-image:url('background.png');
    background-repeat: repeat-x;
}

#top_menu {
    text-align: right;
    position:relative;
    right:30px;
    top:0px;
}
.menu_class a:link {
    color:gray; 
    font-size:10pt;  
    font-family:Arial; 
     text-decoration: underline;
}
.menu_class a:visited {
         color:gray; 
         font-size:10pt; 
         font-weight:normal;  
         font-family:Arial; 
         text-decoration: underline;
}
a.links {
        display: block;
        padding-top: 24px;
        height: 46px;
        width: 200px;
        color: #484848;
        font-family: Arial, sans-serif;
        font-size:18px;
        font-weight: bold;
        text-decoration: none;
}
a.links:hover {
        display: block;
        padding-top: 24px;
        height: 46px;
        width: 200px;
        color: gray;
        font-family: Arial, sans-serif;
        font-size:18px;
        font-weight: bold;
        text-decoration: none;
}
h1 {
        color:#3366CC; 
        font-size:25pt; 
        font-weight:bold;  
        font-family:Arial; 
        text-align: left;
        margin-top: 60px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: 100px;
        border: 0px solid #000000;
}
#form {
     position:relative;
     left:87px;
     top:40px;
        width:500px;
}
span.field {
        text-align:left;
        direction:ltr;
        color:#505050; 
        font-size:12pt;
        font-weight:bold;  
        font-family:Arial;
}
p.failed {
        text-align:left;
        direction:ltr;
        color:red; 
        font-size:15pt;
        font-weight:bold;  
        font-family:Arial;
}
span.succed {
    text-align:left;
 direction:ltr;
 color:green; 
 font-size:12pt;
 font-weight:normal;  
 font-family:Arial;
}
p.succed {
 text-align:left;
 direction:ltr;
 color:green; 
 font-size:15pt;
 font-weight:bold;  
 font-family:Arial;
}
span.errors {
        text-align:left;
        direction:ltr;
        color:red; 
        font-size:10pt;
        font-weight:normal;  
        font-family:Arial;
}
span.failed {
        text-align:left;
        direction:ltr;
        color:red; 
        font-size:10pt;
        font-weight:bold;  
        font-family:Arial;
}
#register_message {
        position:relative;
        left:100px;
        top:17px;
        width:450px;
        border: 0px solid #000000;
}
table#registertable  { 
        border: 0px solid #000000;
        border-right: 0px solid #000000;
}
#copyrights {
    clear:both;
    padding:80px 0px 15px;
    text-align:center;
    color:gray; 
    font-size:10pt;  
    font-family:Arial; 
}
.button {
        border: 1px solid #505050;
        background: #f5f5f5;
        cursor:pointer;
        width: 100px;
        padding-left:5px;
        padding-right:5px;
        padding-bottom:5px;
        padding-top:5px;
        text-align: center;
        text-align:center;
        color:#505050; 
        font-size:12pt;
        font-weight:bold;  
        font-family:Arial;
}
label {
        display: block;
        width: 180px;
        float: left;
        margin: 2px 4px 6px 4px;
        text-align: left;
}
#submit {
        color: #fff;
        font-size: 0;
        width: 68px;
        height: 28px;
        border: none;
        background: #ffffff url(signin_btn.bmp) 0 0 no-repeat;
        cursor:pointer;
}
}
</style>
</head>
</html>

בול מה שיש בקובץ.

בקשר לקידוד, איך שומרים קידוד כזה?

yNaxon 01-03-10 23:46

נסה במקום
קוד:

echo '<meta http-equiv="refresh" content="10;url=index.php" />';
לכתוב:
קוד:

header("location: index.php");
רק תזכור להוסיף:

קוד:

ob_start();
אחרי השורה הראשונה
<?php

dor77 02-03-10 01:50

לא..
עכשיו יש שלשושה הודעות כאלה:

Warning: Cannot modify header information - headers already sent by (output started at c:\wamp\www\a\sign_in.php:1) in c:\wamp\www\a\sign_in.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at c:\wamp\www\a\sign_in.php:1) in c:\wamp\www\a\sign_in.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at c:\wamp\www\a\sign_in.php:1) in c:\wamp\www\a\sign_in.php on line 19

זה הקוד..למקרה שטעיתי..:


PHP קוד:

<?php
ob_start
();
mysql_connect("localhost""root""");
mysql_select_db("phpmyadmin"); 
$user_name mysql_real_escape_string(htmlspecialchars($_POST['user_name']));
$password mysql_real_escape_string(htmlspecialchars(md5($_POST['password'])));
$query mysql_query("SELECT * FROM users WHERE user_name='$user_name'"); 
$row=mysql_fetch_array($query);
$row_password=$row['password'];
$row_user_name=$row['user_name'];
$password_cookie=$row['password'];
$user_name_cookie=$row['user_name'];
if (isset(
$_POST['submit']))
{
if (
$row_password==$password && $row_user_name==$user_name)
{
    
setcookie("username"$user_nametime()+60000);
    
setcookie("id"$id_cookietime()+60000);
        
header("location: index.php");
}
  else
{
        echo 
'
    
        <div id="top_menu">
        <span class="menu_class">
        <a href="sign_in.php">Login</a>&nbsp;&nbsp;
        <a href="sign_up.php">Register</a>
        </span>
        </div>
        
        <h1>Login to your account...</h1> 
        
          <div id="register_message"><p class="failed">Login Fail!</p>
        <span class="failed">Please check your deatiles and try again.</span></div> 
        
        <div id="form">
        <form action="" method="POST">
        <table id="registertable" cellpadding="10" border="0">
        <tr>
            <td align="left">
                <span class="field">Username:</span>
            </td>
            <td align="left">
                    <input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
            </td>
        </tr>
        <tr>
            <td align="left">
                <span class="field">Password:</span>
            </td>
            <td align="left">
                <input type="Password" name="password" id="password" dir="ltr"  value="" style="width:200px;" maxlength="15">
            </td>      
        <tr>
            <td align="right"></td>
            <td align="center">
                <label>&nbsp; </label><input type="submit" name="submit" value="" id="submit" />
            </td> 
        </tr>
        </table>
        </form>
        </div>
    
        <div id="copyrights">
        © All rights reserved.
        </div>
}
        '
;
}

}
else
{
        echo 
'
    
        <div id="top_menu">
        <span class="menu_class">
        <a href="sign_in.php">Login</a>&nbsp;&nbsp;
        <a href="sign_up.php">Register</a>
        </span>
        </div>
        
        <h1>Login to your account...</h1> 
        
        <div id="form">
        <form action="" method="POST">
        <table id="registertable" cellpadding="10" border="0">
        <tr>
            <td align="left">
                <span class="field">Username:</span>
            </td>
            <td align="left">
                    <input type="text" name="user_name" id="user_name" dir="ltr" value="" style="width:200px;" maxlength="50">
            </td>
        </tr>
        <tr>
            <td align="left">
                <span class="field">Password:</span>
            </td>
            <td align="left">
                <input type="Password" name="password" id="password" dir="ltr"  value="" style="width:200px;" maxlength="15">
            </td>      
        <tr>
            <td align="right"></td>
            <td align="center">
                <label>&nbsp; </label><input type="submit" name="submit" value="" id="submit" />
            </td> 
        </tr>
        </table>
        </form>
        </div>
    
        <div id="copyrights">
        © All rights reserved.
        </div>
        '
;
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Your Private Homepage</title>
    <meta  http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
body {
    background-image:url('background.png');
    background-repeat: repeat-x;
}

#top_menu {
    text-align: right;
    position:relative;
    right:30px;
    top:0px;
}
.menu_class a:link {
    color:gray; 
    font-size:10pt;  
    font-family:Arial; 
     text-decoration: underline;
}
.menu_class a:visited {
         color:gray; 
         font-size:10pt; 
         font-weight:normal;  
         font-family:Arial; 
         text-decoration: underline;
}
a.links {
        display: block;
        padding-top: 24px;
        height: 46px;
        width: 200px;
        color: #484848;
        font-family: Arial, sans-serif;
        font-size:18px;
        font-weight: bold;
        text-decoration: none;
}
a.links:hover {
        display: block;
        padding-top: 24px;
        height: 46px;
        width: 200px;
        color: gray;
        font-family: Arial, sans-serif;
        font-size:18px;
        font-weight: bold;
        text-decoration: none;
}
h1 {
        color:#3366CC; 
        font-size:25pt; 
        font-weight:bold;  
        font-family:Arial; 
        text-align: left;
        margin-top: 60px;
        margin-right: 0px;
        margin-bottom: 0px;
        margin-left: 100px;
        border: 0px solid #000000;
}
#form {
     position:relative;
     left:87px;
     top:40px;
        width:500px;
}
span.field {
        text-align:left;
        direction:ltr;
        color:#505050; 
        font-size:12pt;
        font-weight:bold;  
        font-family:Arial;
}
p.failed {
        text-align:left;
        direction:ltr;
        color:red; 
        font-size:15pt;
        font-weight:bold;  
        font-family:Arial;
}
span.succed {
    text-align:left;
 direction:ltr;
 color:green; 
 font-size:12pt;
 font-weight:normal;  
 font-family:Arial;
}
p.succed {
 text-align:left;
 direction:ltr;
 color:green; 
 font-size:15pt;
 font-weight:bold;  
 font-family:Arial;
}
span.errors {
        text-align:left;
        direction:ltr;
        color:red; 
        font-size:10pt;
        font-weight:normal;  
        font-family:Arial;
}
span.failed {
        text-align:left;
        direction:ltr;
        color:red; 
        font-size:10pt;
        font-weight:bold;  
        font-family:Arial;
}
#register_message {
        position:relative;
        left:100px;
        top:17px;
        width:450px;
        border: 0px solid #000000;
}
table#registertable  { 
        border: 0px solid #000000;
        border-right: 0px solid #000000;
}
#copyrights {
    clear:both;
    padding:80px 0px 15px;
    text-align:center;
    color:gray; 
    font-size:10pt;  
    font-family:Arial; 
}
.button {
        border: 1px solid #505050;
        background: #f5f5f5;
        cursor:pointer;
        width: 100px;
        padding-left:5px;
        padding-right:5px;
        padding-bottom:5px;
        padding-top:5px;
        text-align: center;
        text-align:center;
        color:#505050; 
        font-size:12pt;
        font-weight:bold;  
        font-family:Arial;
}
label {
        display: block;
        width: 180px;
        float: left;
        margin: 2px 4px 6px 4px;
        text-align: left;
}
#submit {
        color: #fff;
        font-size: 0;
        width: 68px;
        height: 28px;
        border: none;
        background: #ffffff url(signin_btn.bmp) 0 0 no-repeat;
        cursor:pointer;
}
}
</style>
</head>
</html>

תודה (:

יניב בן צבי 02-03-10 02:24

יש לך בעיה בקידוד של הקובץ הפעלתי את הקוד ואין שגיאה... תשנה את הקידוד לANSI אפשרי בעזרת הכתבן הרגיל או בעזרת תוכנת עריכה כלשהי אני משתמש בeclipse

dor77 02-03-10 02:32

תודה..עובד..
אבל שנייה אני חייב להבין...
בקבוץ עתמו הגדרתי כutf וכמובן גם בשמירת הקובץ..
עכשיו שיניתי ל ANSI..אני צריך למחוק את השורה הזו:

PHP קוד:

    <meta  http-equiv="content-type" content="text/html;charset=utf-8" /> 

או שלשנות משהו??
עוד משהו..לשנות את הקחדוד של כל הדפים לANSI או רק של הדף הזה?

תודה.

יניב בן צבי 02-03-10 02:43

תשמור בansi
ותשתמש בזה
PHP קוד:

<meta  http-equiv="content-type" content="text/html;charset=windows-1255" /> 


dor77 02-03-10 16:21

אוקיי..תודה אבל שאלה..
אני אשנה את הקידוד רק לדף הזה עם העוגיות ואת כל שאר הדפים אני אשאיר כמו שהוא? (utf).
עוד משהו..הדף הזה ששמור בwindows-1255 הוא דף באנגלית, זה בסדר?

תודה.

Shay Ben Moshe 02-03-10 19:50

אל תקשיב לזה.
לעבוד תמיד בUTF8, בהמשך תגלה הרבה מאוד יתרונות על פני ANSI.
בכל אופן, לפתרון הבעיה שלך תצטרך לשמור את הקובץ כUTF8 Without BOM. אתה מוזמן לגגל את זה.
אתה יכול להשתמש בעורך כמו NOTEPAD++ בשביל לשמור את זה ככה, מאוד מאוד פשוט ונוח.

dor77 03-03-10 22:22

יש לי notepad++..
עשיתי שמירה בשם, ואז ב"שמור כסוג" אין לי אל סוג הקדוד שאמרת.
עוד משהו..כשאני שומר את זה בקידוד הזה, אני משאיר את השורה של הutf כמו שהיא?
ועוד פעם, רק את הדף הזהנ אני משנה, את כל השאר אני משאיר utf רגיל?

תודה.


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

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