![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 176 Pomógł: 0 Dołączył: 27.06.2002 Skąd: Stalowa Wola Ostrzeżenie: (0%) ![]() ![]() |
Ponizej mam skrypt ktory wykonuje formularz logowania (login, password).
Jednak nie wiem jak zabezpieczyc np. wszystkie skrypty na stronie - aby nikt nie zalogowany - nie mogl go uruchomic. Tzn jaki kod wstawic przed kazdym skryptem, aby go nie mozna bylo uruchomic jesli sie nie jest zalogowanym na stronie? ![]() [php:1:be26129778] <? /* Check User Script */ session_start(); // Start Session include 'db.php'; // Conver to simple variables $username = $_POST['username']; $password = $_POST['password']; if((!$username) || (!$password)){ echo "Please enter ALL of the information! <br />"; include 'login_form.html'; exit(); } // Convert password to md5 hash $password = md5($password); // check if the user info validates the db $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } // Register some session variables! session_register('first_name'); $_SESSION['first_name'] = $first_name; session_register('last_name'); $_SESSION['last_name'] = $last_name; session_register('email_address'); $_SESSION['email_address'] = $email_address; session_register('special_user'); $_SESSION['user_level'] = $user_level; mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'"); header("Location: login_success.php"); } } else { echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br /> Please try again!<br />"; include 'login_form.html'; } ?>[/php:1:be26129778] |
|
|
![]()
Post
#2
|
|
![]() Grupa: Zarejestrowani Postów: 56 Pomógł: 0 Dołączył: 10.03.2003 Skąd: Szczecin Ostrzeżenie: (0%) ![]() ![]() |
Można np. tak:
[php:1:84f354d856]<?php session_start( ); if( session_is_registered( 'username' ) ) { echo( 'OK' ); } else { echo( 'Zaloguj się...' ) } ?>[/php:1:84f354d856] poza tym, nie jest końeczne stosowanie obu tych metod: [php:1:84f354d856] session_register('first_name'); $_SESSION['first_name'] = $first_name; [/php:1:84f354d856] wystarczy jedena z nich, raczej ta druga. |
|
|
![]() ![]() |
![]() |
Aktualny czas: 19.08.2025 - 08:57 |