![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 2 Pomógł: 0 Dołączył: 26.05.2009 Ostrzeżenie: (0%) ![]() ![]() |
hello
Kozystajac z poradnika: http://www.internetmaker.pl/artykul/430,1,...one_haslem.html zrobilem strone z logowaniem i wszystko smiga elegancko, tylko potrzebuje podzielic logowanie na "poziom dostępu", tak aby jesli zaloguje sie jako odmin przenioslo mnie na strone approf1.php, a jesli jako user to profil.php. W tej chwili przenosi mnie do strony profil.php, dlatego ze w grupie mam tylko okreslony rodzaj uzytkownika 'user', moge dodać to tego jeszcze 'admin', ale wowczas czy zaloguje sie jako admin czy user zawsze przenesie mnie do profil.php :/ Tak wyglada kod php pliku logowanie.php ponizej tego kodu jest jeszcze kod html z formulaem do logowania, tekstem itp: CODE <?php require_once('../Connections/polaczenie.php'); ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['login'])) { $loginUsername=$_POST['login']; $password=$_POST['password']; $MM_fldUserAuthorization = "access"; $MM_redirectLoginSuccess = "profil.php"; $MM_redirectLoginFailed = "logowanie.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_polaczenie, $polaczenie); $LoginRS__query=sprintf("SELECT login, password, access FROM users WHERE login='%s' AND password='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $polaczenie) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'access'); //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> A tak wyglada kod php pliku profil.php. plik ten jest chroniony i jesli uzytkownik nie jest zalogowany to zostaje przeniesiony do strony logowanie.php CODE <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = "user"; $MM_donotCheckaccess = "false"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && false) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "logowanie.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer .= "?" . $QUERY_STRING; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> I tak jak pisalem wyzej chodzi o to ze gdy bede probowal sie zalogować jako admin, to zamiast do strony profil.php trafi do strony approf1.php (która narazie jst pusta ![]() ![]() |
|
|
![]() ![]() |
![]() |
Aktualny czas: 22.08.2025 - 09:31 |