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

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

InetKey.Net 16-07-08 17:51

שאלה בקשר לsession בPHP
 
שלום , יש לי טופס התחברות :
PHP קוד:

<?php
session_start
();

if (!empty(
$logincheck)){
function 
checkLvl($checkuser$checkpass) {
    
$query1 mysql_query("SELECT * FROM customer WHERE username='$checkuser' AND password='$checkpass'") or die(mysql_error());
    if(
mysql_num_rows($query1) > 0){
        return 
1;
    }
    
$query2 mysql_query("SELECT * FROM useradmin WHERE username='$checkuser' AND password='$checkpass'") or die(mysql_error());
    if(
mysql_num_rows($query2) > 0){
        return 
2;
    }
    
$query3 mysql_query("SELECT * FROM technicals WHERE username='$checkuser' AND password='$checkpass'") or die(mysql_error());
    if(
mysql_num_rows($query3) > 0){
        return 
3;
    }
    
$query4 mysql_query("SELECT * FROM sellers WHERE username='$checkuser' AND password='$checkpass'") or die(mysql_error());
    if(
mysql_num_rows($query4) > 0){
        return 
4;
    }
}
$userlevel checkLvl($checkuser$checkpass);
    if (empty(
$userlevel)) {
    print 
"$admin_loginfail";
    exit;
    }else{    
$_SESSION["loginuser"] = $userlevel;
session_register("loginuser");
    
$loginuser $checkuser;
    
$_SESSION["loginuserid"] = $tempid;
    
session_register("loginuserid");
    
$loginuserid $tempid;
    }
if(
$userlevel == 1){
    echo 
'<HEAD>
<SCRIPT language="JavaScript">
<!--
window.location="customer/index.php";
//-->
</SCRIPT>
</HEAD>'
;
} else if(
$userlevel == 2){
        echo 
'<HEAD>
<SCRIPT language="JavaScript">
<!--
window.location="index.php";
//-->
</SCRIPT>
</HEAD>'
;
} else if(
$userlevel == 3){
    echo 
'<HEAD>
<SCRIPT language="JavaScript">
<!--
window.location="tech/index.php";
//-->
</SCRIPT>
</HEAD>'
;
} else if(
$userlevel == 4){
    echo 
'<HEAD>
<SCRIPT language="JavaScript">
<!--
window.location="sell/index.php";
//-->
</SCRIPT>
</HEAD>'
;
}
}
?>
<?php
if (!(session_is_registered("loginuser"))){
?>
<html>
<head>
<title><?php print "$admin_login"?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php print "$admin_charset"?>">
<link rel="stylesheet" href="style/style.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<form action="<?php print "$PHP_SELF"?>" method="POST">
<?
if (count($HTTP_POST_VARS)) {
       while (list(
$key$val) = each($HTTP_POST_VARS)) {
       print 
"<input type=\"hidden\" name=\"$key\" value=\"$val\">\n";
      }
}

if (
count($HTTP_GET_VARS)) {
       while (list(
$key$val) = each($HTTP_GET_VARS)) {
       print 
"<input type=\"hidden\" name=\"$key\" value=\"$val\">\n";
      }
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td align="center" valign="top"> 
      <hr width="90%" size="1" noshade>
      <table width="90%" border="0" cellspacing="0" cellpadding="4" height="300">
        <tr> 
          <td align="center"> 
            <p><?php print "$admin_login"?></p>
            <table width="300" border="0" cellspacing="1" cellpadding="4" bgcolor="#F2F2F2">
              <tr bgcolor="#FFFFFF"> 
                <td width="83"><?php print "$admin_username"?> :</td>
                <td width="198"><input type="text" name="checkuser"></td>
              </tr>
              <tr bgcolor="#FFFFFF"> 
                <td><?php print "$admin_password"?> :</td>
                <td><input type="password" name="checkpass"></td>
              </tr>
              <tr bgcolor="#FFFFFF"> 
                <td>&nbsp;</td>
                <td><input type="submit" name="logincheck" value="<?php print "$admin_ok"?>"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
  <tr>
    <td align="center" valign="top" height="40">&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
<?php
exit;
}
?>

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

מה שבעצם אני רוצה לעשות זה לקבוע שם אחר לsession , כלומר שיעשה register session עם שם שונה לכל עמוד כדי שמשתמש רגיל לא יוכל להכנס למנהל ראשי..ובindex של העמוד לקבוע if שיעשה בדיקה עם הסיישן registered.

איך אפשר לעשות את זה? אני לא מצליח...
תודה רבה לעוזרים

stel222 17-07-08 11:28

בעמוד של המנהלים תבדוק שהSESSION לא אותו שם של הcustomer זאת כנראה הבעיה אתה צריך שכל קבוצה יהיה SESSION אחר

BlueNosE 17-07-08 11:36

סתם מעצבן שבאים לפה ומביאים קודים באורך 400 שורות..
תמקד את הבעיה. איפה הקושי?


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

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