Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]logowanie a sesja
damian-rac
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 13.01.2009
Skąd: PL

Ostrzeżenie: (0%)
-----


mam formularz do rejestracji użytkownków (do bazy) i do logowania. szablon strony oparty o smarty. chodzi mi o to, żeby zrobić tak, że jak sie zaloguje to żeby pokazywalo w menu dodatkowy link 'zarządzaj kontem' 

niby wszystko łatwo prosto, ale nie funkczy

w pliku config.php (ze smartow) rozpoczynam sesje

Kod
<?php

session_start();

require_once("libs/Smarty.class.php");

$smarty = new Smarty;
$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'templates_c/';
$smarty->cache_dir = 'cache/';
$smarty->config_dir = 'configs/';

define('DB_HOST', 'aaa');
define('DB_USER', 'aaa');
define('DB_PASSWORD', 'aaa');
define('DB_DATABASE', 'aaa');
?>




kod login_exe.php wygląda tak

Kod
<?php
 //Start session
 session_start();
 //$_session['admin'];

 //Include database connection details
 require_once('config.php');
 
 //Array to store validation errors
 $errmsg_arr2 = array();
 
 //Validation error flag
 $errflag = false;
 
 //Connect to mysql server
 $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
 if(!$link) {
     die('Failed to connect to server: ' . mysql_error());
 }
 
 //Select database
 $db = mysql_select_db(DB_DATABASE);
 if(!$db) {
     die("Unable to select database");
 }
 
 //Function to sanitize values received from the form. Prevents SQL injection
 function clean($str) {
     $str = @trim($str);
     if(get_magic_quotes_gpc()) {
         $str = stripslashes($str);
     }
     return mysql_real_escape_string($str);
 }
 
 //Sanitize the POST values
 $login = clean($_POST['login']);
 $password = clean($_POST['password']);
 
 //Input Validations
 if($login == '') {
     $errmsg_arr2[] = 'Pole &quot; login &quot; pozostało puste. ';
     $errflag = true;
 }
 if($password == '') {
     $errmsg_arr2[] = 'Pole &quot; hasło &quot; pozostało puste. ';
     $errflag = true;
 }
 
 //If there are input validations, redirect back to the login form
 if($errflag) {
     $_SESSION['ERRMSG_ARR2'] = $errmsg_arr2;
     session_write_close();
     header("location: login_form.php");
     exit();
 }
 
 //Create query
 $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
 $result=mysql_query($qry);
 
 //Check whether the query was successful or not
 if($result) {
     if(mysql_num_rows($result) == 1) {
         //Login Successful
         session_regenerate_id();
         $member = mysql_fetch_assoc($result);
         $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
         $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
         $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
         session_write_close();
         header("location: member_index.php");
         exit();
     }else {
         //Login failed
         header("location: login_failed.php");
         exit();
     }
 }else {
     die("Query failed");
 }

?>




noo i w miejscu gdzie ma byc wyswietlane dodatkowe menu po zalogowaniu

Kod
if($_SESSION['login']!=1)
             echo "
                 <li><a href=member_profile.php>Zarządzaj kontem</a></li>

             ";




skrypt logowania i rejsetracji jest gotowy sciagniety z jakiejs strony PHP-Login.rar

jakies wskazówki jak to zrobić, żeby działało? 

Ten post edytował damian-rac 13.01.2009, 20:49:43
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 06:30