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

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

Avi Salama 27-08-08 23:38

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

נתחיל מהדף login, שאותו עשיתי עם סיישן.
PHP קוד:

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<
tr>
<
form name="form1" method="post" action="checklogin.php">
<
td>
<
table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<
tr>
<
td colspan="3"><strong>Member Login </strong></td>
</
tr>
<
tr>
<
td width="78">Username</td>
<
td width="6">:</td>
<
td width="294"><input name="myusername" type="text" id="myusername"></td>
</
tr>
<
tr>
<
td>Password</td>
<
td>:</td>
<
td><input name="mypassword" type="text" id="mypassword"></td>
</
tr>
<
tr>
<
td>&nbsp;</td>
<
td>&nbsp;</td>
<
td><input type="submit" name="Submit" value="Login"></td>
</
tr>
</
table>
</
td>
</
form>
</
tr>
</
table

הדף checklogin.php:
PHP קוד:

<?php
$host
="localhost"// Host name 
$username="zvaim_new"// Mysql username 
$password="000000"// Mysql password 
$db_name="zvaim_new"// Database name 
$tbl_name="members"// Table name 

// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:index.php");
}
else {
echo 
"Wrong Username or Password";
}
?>

הדף logout.php
PHP קוד:

<? 
session_start
();
session_destroy();
?>

והדף הראשי של המערכת (מה שאני רוצה לעשות שאם אני לא מחובר אל המערכת, אז לא יהיה ניתן להכנס לדף הראשי של המערכת, אלא הוא יעביר אותי אוטומטית אל הדף login.php.

index.php - הדף הראשי של המערכת
PHP קוד:

<? 
session_start
();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>CMS</title>
</head>
<body>

            <div class="wrep">
                <div id="header">
                      <img src="images/bar.png" width="900" height="130" alt="" />

                <div id="menu">    
                          <div class="menu_text">
                          <a href="index.html">דף ראשי</a>
                                                                                                            <br />
                                                                                                            <a href="edit.php">עריכת דפים</a>
                                                                                                            <br />
                                                                                                            <a href="edit.php">עריכת חבילות</a>
                                                                                                            <br />
                                                                                                            <a href="logout.php">התנתק</a>
                          </div>
                </div>
            </div>

                                                                       <div id="tail_right">
                        <div class="title_text" style="margin-top: 15px;">
                                                                                                             ברוך הבא<br />
                                                                                </div>
                                                                       </div>

           </div>

</body>
</html>


dabi 27-08-08 23:40

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

Erez | TrustMedia.co.il 28-08-08 10:36

לא רשמת בראש העמוד check_login את הפונקציה session_start

Daniel 28-08-08 11:17

ציטוט:

נכתב במקור על ידי EAStyle (פרסם 663212)
לא רשמת בראש העמוד check_login את הפונקציה session_start

HTML קוד:

If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start() before use.
ולנושא - מה הבעייה?

NoWaySkill 30-08-08 01:38

תרשום
PHP קוד:

// this start the session
session_start(); 


אחי ד"א מומלץ שתצפין את הסיסמאות שלך כן ובמיוחד אם אתה בונה CMS..
תעשה ככה:
PHP קוד:

sha1($password); 

ותאחסן תסיסמא במסד ככה יותר מאובטח

Daniel 30-08-08 10:10

ציטוט:

נכתב במקור על ידי NoWaySkill (פרסם 663819)
תרשום
PHP קוד:

// this start the session
session_start(); 


אחי ד"א מומלץ שתצפין את הסיסמאות שלך כן ובמיוחד אם אתה בונה CMS..
תעשה ככה:
PHP קוד:

sha1($password); 

ותאחסן תסיסמא במסד ככה יותר מאובטח

זה לא יעזור לו, אף אחד לא מקדיש דקה לקרוא?

ibmod 30-08-08 11:31

הנה:
PHP קוד:


if(isset($_SESSION['myusername']))  //האם יש סיישן
{
// פה יופיע הדף כאשר אתה מחובר
} else {
// פה יופיע משהו במידה ואתה לא מחובר


ובעצם אתה מבצע פה בדיקה האם קיים סיישן במידה וכן אז.... בלה בלה


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

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