Форум: Форум PHPФорум ApacheФорум Регулярные ВыраженияФорум MySQLHTML+CSS+JavaScriptФорум FlashРазное
Новые темы: 0000000
PHP 5. На примерах. Авторы: Кузнецов М.В., Симдянов И.В., Голышев С.В. C++. Мастер-класс в задачах и примерах. Авторы: Кузнецов М.В., Симдянов И.В. MySQL 5. В подлиннике. Авторы: Кузнецов М.В., Симдянов И.В. PHP на примерах (2 издание). Авторы: Кузнецов М.В., Симдянов И.В. Объектно-ориентированное программирование на PHP. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум PHP

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум (новые сообщения вниз) Структурный форум

тема: Не работает аутентификация на сессиях

Сообщения:  [1-2] 

 
 автор: DEM   (06.08.2011 в 12:44)   письмо автору
 
   для: veretilo_sergei   (06.08.2011 в 12:37)
 

Из того, что понял в коде:
Вы выводите переменную $auth_user, которая вначале у вас передаётся в запросе. Но это не $_SESSION['auth_user'] (который вы, кажется, вообще не выводите), поэтому при обновлении страницы она у вас и пропадает... Хотя я мог просто не досмотреть код...


PS. теперь сессии лучше определять так: $_SESSION['auth_user'] = "значение", потому что функция session_registe(); устарела и в ближайших версиях будет удалена

  Ответить  
 
 автор: veretilo_sergei   (06.08.2011 в 12:37)   письмо автору
 
 

люди добрые подскажите, что надо изменить в коде для его работоспособности
после аутентификации в переменной auth_user сохр имя пользователя, после нажатия на кнопку account-setup переменная auth_user становиться "пустой" и происходит снова аутентификация. не могу понять. я новичок. помогите, пожалуйста!

<?php
//include("include_fns.php");
//////////////////////////////// //////////////////////////////// //////////////////////////////// //////////////////////////////// //////////////////////////////// //////////////////////////////// /////////////////

function do_html_header($auth_user,$title="",$selected_account)
{
global $table_width;
?>
<html>
<head>
<title><? echo "$title";?></title>
<style>
h1 { font-family: 'Comic Sans MS', sans-serif; font-size: 32;
font-weight: bold; color: black; margin-bottom: 0}
b { font-family: 'Arial', sans-serif; font-size: 13;
font-weight: bold; color: black }
th { font-family: 'Comic Sans MS', sans-serif; font-size: 18
font-weight: bold; color: black; }
body, li, td { font-family: Arial, Helvetica, sans-serif;
font-size: 12; margin = 5px }
a { color: #000000 }
</style>
</head>
<body>
<table width = 1635 cellspacing = 0 cellpadding = 3 bgcolor = "#ff6600" border = 0>
<tr bgcolor = "#ff6600">
<td bgcolor = "#ff6600" width = 103><img src = "images/warm-mail.gif"
width = 103 height = 45 alt ="" valign = middle></td>
<td bgcolor = "#ff6600" width = <?=$table_width-110;?>><h1><? echo "$title";?></h1></td>
<?
//if(number_of_accounts($auth_user)>1)
//{
//echo "<form target='index.php?action=open-mailbox' method=post>";
//echo '<td bgcolor = "#ff6600" align = right valign = middle>';
//display_account_select($auth_user, $selected_account);
//echo '</td>';
//echo "</form>";
//}
?>
</tr>
</table>
<table width = <?=$table_width?> cellpadding = 0 cellspacing = 0 border = 0>
<tr><td>

<?
}

function display_toolbar($buttons,$extra_parameters = '')
{
global $table_width;

echo "<table width = 1635 cellpadding = 0 cellspacing = 0 border = 0>";
echo '<tr>';
echo '<td bgcolor = "#cccccc" align = center>';
for($i = 0; $i < 5; $i++)
{
if (isset($buttons[$i]))
display_button($buttons[$i], $extra_parameters);
else
display_spacer();
}
echo '</td>';
echo '</tr>';
echo '</table>';
}

function display_spacer()
{
echo "<img src = 'images/spacer.gif' border = 0 width = 149 height = 43 alt = ''>";
}

function display_button($button, $extra_parameters = '')
{
$url = "index.php?action=$button";
if($extra_parameters)
$url .= $extra_parameters;
echo "<a href = '$url'>";
echo "<img src = 'images/$button.gif' border = 0 ";
echo "width = 149 height = 43 ";
echo "alt = '".format_action($button)."'></a>";
}

//function display_form_button($button)
//{
//echo "<input type="image" src='images/".$button.".gif' border = 0 ";
//echo "width = 149 height = 43 ";
//echo "alt = '".format_action($button)."'></a>";
//}

function display_login_form($action)
{
?>
<center>
<form action="index.php?action=<?=$action?>" method=post>
<table bgcolor='#cccccc' border = 0 cellpadding = 6 cellspacing = 0>
<th colspan = 2 bgcolor = '#ff6600'>Log in</th>
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="username">
</td>
</tr>
<tr>
<td>
Password:
</td>
<td><input type="text" name="passwd"</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="submit" name="login" value="Log in"</td>
</td>
<tr>
</table>
</form>
</center>
<?
}

function format_action($string)
{
// convert our actions into a displayable string
// eg "account-setup" becomes "Account Setup"
$string = str_replace("-", " ", $string);
$string = ucwords($string);
return $string;
}


function check_auth_user()
{
global $auth_user;
if (isset($_SESSION["auth_user"]))
return true;
else
return false;

}

function login($username,$password)
{
mysql_connect("localhost", "root", "") or die("Could not connect: ".mysql_error());
mysql_select_db("mail") or die("Could not select database: ".mysql_error());
$query="select * from users where username='$username' and password='$password'";
$result=mysql_query($query);
if(mysql_num_rows($result)>0)
return true;
else
return false;
}

function number_of_accounts($auth_user)
{
mysql_connect("localhost", "root", "") or die("Could not connect: ".mysql_error());
mysql_select_db("mail") or die("Could not select database: ".mysql_error());

$query="select count(*) from accounts where username='$auth_user'";
$result=mysql_query($query);
return mysql_result($result, 0, 0);
}

function get_account_list($auth_user)
{
$query="select accountid from accounts where username='$auth_user'";
$list=array();

mysql_connect("localhost", "root", "") or die("Could not connect: ".mysql_error());
mysql_select_db("mail") or die("Could not select database: ".mysql_error());
$result=mysql_query($query);
$num=mysql_num_rows($result);
for($i=0;$i<$num;$i++)
{
array_push($list,mysql_result($result,$i,0));
}
return $list;
}

function display_account_setup($auth_user)
{

}


//////////////////////////////// //////////////////////////////// //////////////////////////////// //////////////////////////////// //////////////////////////////// //////////////////////////////// ///////////
session_start();
ini_set("register_globals",1);
$buttons=array();
$status="";

if(isset($_REQUEST['username']) && isset($_REQUEST['passwd']))
{
if(login($_REQUEST['username'],$_REQUEST['passwd']))
{
$status.="<p>Logged in sucsesfully <br><br><br><br><br><br>";
$auth_user=$_REQUEST['username'];
session_register("auth_user"); //////////////////////////////// ///////////////// session_register($auth_user);
echo $auth_user;
if(number_of_accounts($auth_user)==1)
{
$accounts = get_account_list($auth_user);
$selected_account = $accounts[0];
session_register("selected_account");
}

}
else
{
$status .= "<p>Sorry, we could not log you in with that
username and password.<br><br><br><br><br><br>";
}
}

$buttons[0]="view-mailbox";
$buttons[1]="new-message";
$buttons[2]="account-setup";

if(isset($auth_user))
{
$buttons[4] = 'log-out';
}

@do_html_header($auth_user,"Warm Mail",$selected_account);
@display_toolbar($buttons);
echo $status;
echo $auth_user."+-+";
if(!isset($auth_user))
{
echo "<p>You need to log in";
if(@$action&&$action!='log-out')
echo " to go to ".format_action($action);
echo ".<br><br>";
display_login_form($action);
}
else
{
switch($_GET['action'])
{
case 'account-setup' :
{
echo "++++++++++++++++++++++++++";
display_account_setup($auth_user);
break;
}


}


}
























?>

  Ответить  

Сообщения:  [1-2] 

Форум разработан IT-студией SoftTime
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования