PDA

View Full Version : چرا $_SESSION ها مقدار مناسب ندارند؟



programmer_forever
شنبه 15 اسفند 1388, 19:14 عصر
با سلام خدمت دوستان عزیز.
ببخشید من روی یه پروژه دارم کار می کنم.به یه مشکل بر خوردم.
اگه میشه لطف کنید کمکم کنید.
قراره در صفحه login.php کابر فرم شامل یوزر و پس خود را وارد کند. در صورت valid بودن کاربر (در بانک از قبل تعریف شده باشد) meta tag ، refresh اجرا شده و پس از 3 ثانیه کاربر را به صفحه ی cpanel.php هدایت میکند.ولی مشکل اینجاست که در این صفحه $_SESSION ها مقدار ندارند و لینک های مربوط به مدیر نشان داده نمیشود.
این ها کد های صفحه ی login.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">
<head>
<link type="text/css" href="style.css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="fa">
<title>ورود به کنترل پنل</title>
</head>

<body>
<?php
include "db.php";
/*conneting to DB and select it*/
mysql_connect("$hostname","$username","$password") or die("Invalid connect");
mysql_select_db("$db") or die ("Invalid select");
/*this is a query that shows if user is defined in DB or not*/
$select=mysql_query("select * from operators where (username='$_POST[username]' and password='$_POST[password]')");
/*fetching query above*/
$login=mysql_fetch_array($select);
/*checking if user is defined in DB or not*/
if($login)
{
/*giving $_SESSION the value of the elements of log in form to know if user has logged in or not every where we want*/
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];
/*telling the web browser to automatically move to cpanel.php page*/
echo '<div class="refresh">شما در حال منتقل شدن به صفحه مدیریتی خود هستید. لطفاً صبر کنید.
<br /><br />اگر پس از سه ثانیه به صفحه مدیریتی خود منتقل نشدید لینک زیر را کلیک کنید.<br /><br /><a href="cpanel.php">انتقال به صفحه مدیریتی</a></div>

<META
HTTP-EQUIV="Refresh"
CONTENT="3; URL=cpanel.php">
';
}
/*this else works only the first time page loads or if user enters wrong "username" or "password"*/
else {

?>
<!-- this is the div for the whole body of this page -->
<div class="body">
<!-- this is the div contains log in form -->
<div class="login">
<!-- log in form-->
<form action="login.php" method="post" name="log in" dir="rtl" lang="fa">
برای ورود به کنترل پنل نام کاربری و رمز عبور خود را وارد کنید :<br /><br />
<table align="center">
<tr><td align="left">
نام کاربری :
</td><td>
<input name="username" type="text" dir="rtl" lang="fa" size="20" /></td>
</tr><tr>
<td align="left">
رمز عبور :
</td>
<td>
<input name="password" type="password" dir="rtl" lang="fa" size="20" /></td>
</tr><tr>
<td></td><td>
<input name="submit" type="submit" dir="rtl" lang="fa" value="log in" />
</td></tr></table>
</form>


</div>
</div>
<?php
}
?>
</body>

</html>

و اینها مربوط به cpanel.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">
<head>
<link type="text/css" href="style.css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="fa">
<title>کنترل پنل</title>
</head>

<body>
<div class="body">
<?php
include "db.php";
/*conneting to DB and select it*/
mysql_connect("$hostname","$username","$password") or die("Invalid connect");
mysql_select_db("$db") or die ("Invalid select");
/*this is a query that shows if user has logged in or not*/
$select=mysql_query("select * from operators where (username='$_SESSION[username]' and password='$_SESSION[password]')") or die("query");
/*fetching query above*/
$login=mysql_fetch_array($select);
/*checking if user is super admin*/
if($login and $_SESSION['username']=='super_admin')
{
echo "Welcome super admin";
echo '<div class="links"><a href="automation.php">اتوماسیون اداری</a>&nbsp; |<a href="cpanel.php">امکانات من</a>&nbsp; |<a href="cpanel.php">مخاطبان</a>&nbsp; |</div>';
}
else /*checking if user is usual operator*/
if($login and $_SESSION['username']!='super_admin')
{
echo "Welcome operator";
echo '<div class="links"><a href="cpanel.php">امکانات من</a>&nbsp; |<a href="cpanel.php">مخاطبان</a>&nbsp; |</div>';
}
?>

</div>
</body>
</html>
میشه لطف کنید سریع جواب بدید.
واقغاً نمیدونم مشکل کجاست.:ناراحت:

funpatogh
یک شنبه 16 اسفند 1388, 20:01 عصر
صفحه لاگین رو به این تغییر بده


<?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">
<head>
<link type="text/css" href="style.css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="fa">
<title>ورود به کنترل پنل</title>
</head>

<body>
<?php
include "db.php";
/*conneting to DB and select it*/
mysql_connect("$hostname","$username","$password") or die("Invalid connect");
mysql_select_db("$db") or die ("Invalid select");
/*this is a query that shows if user is defined in DB or not*/
$select=mysql_query("select * from operators where (username='$_POST[username]' and password='$_POST[password]')");

/*checking if user is defined in DB or not*/
if(mysql_num_rows($select)>0){



/*giving $_SESSION the value of the elements of log in form to know if user has logged in or not every where we want*/
$_SESSION['username']=$_POST['username'];
$_SESSION['password']=$_POST['password'];
/*telling the web browser to automatically move to cpanel.php page*/
$prompt='META
HTTP-EQUIV="Refresh"
CONTENT="3; URL=cpanel.php">
'.'<div class="refresh">شما در حال منتقل شدن به صفحه مدیریتی خود هستید. لطفاً صبر کنید.
<br /><br />اگر پس از سه ثانیه به صفحه مدیریتی خود منتقل نشدید لینک زیر را کلیک کنید.<br /><br /><a href="cpanel.php">انتقال به صفحه مدیریتی</a></div>';


}
/*this else works only the first time page loads or if user enters wrong "username" or "password"*/
else {
hedaer("location:login.php");


echo(isset($prompt))?$prompt:null;

?>

programmer_forever
یک شنبه 23 اسفند 1388, 18:50 عصر
سلام دوست عزيز ، پروژه كلاً كنسل شد، از اين كه جواب داديد ممنونم/