Jackal Posted May 1, 2006 Report Share Posted May 1, 2006 Nu man ir login skripts viss it kaa strāda, bet es nesaprotu kā liegt pieeju lapai, ja neesi ielogojies, cik saprotu tur ir kaut kas ar sesijām? Paskaidrojiet kā tas notiek, es jau izskatiju šo forumu, bet tāpat neko nesapratu. Link to comment Share on other sites More sharing options...
Vebers Posted May 1, 2006 Report Share Posted May 1, 2006 Kad lietotājs ielogojas, tad ieliec $_SESSION['logged']=true; Tad katrā lapā pārbaudi vai ir $_SESSION['logged'], ja nav, tad nav ielogojies un aizmet uz login lapu vai k-kā tā. Link to comment Share on other sites More sharing options...
Jackal Posted May 1, 2006 Author Report Share Posted May 1, 2006 Nu ja es pārbaudu ar $_SESSION['logged'] tad parāda, ka nav definēts logged kā viņu definēt? Link to comment Share on other sites More sharing options...
Vebers Posted May 1, 2006 Report Share Posted May 1, 2006 (edited) Es jau teicu pie autorizācijas uzliec $_SESSION['logged']=true; un pārbaudi ar if(!isset($_SESSION['logged'])) { header("Location: autorizacija.php"); } Edited May 1, 2006 by MakaTaNaw Link to comment Share on other sites More sharing options...
Jackal Posted May 1, 2006 Author Report Share Posted May 1, 2006 (edited) Kaut kas nesanāk, sheit būs skripti: vinjš mani nelaiž lapā arī ja esmu ielogojies <? $kom=mysql_query("select `nickname`,`password` from users"); while($row=mysql_fetch_array($kom)){ if(isset($_POST['login'])){ $password=$row['password']; $nickname=$row['nickname']; if($_POST['user']==$nickname && $_POST['pass']==$password) { $_SESSION['logged']=true; header("location: forum.php"); } } } ?> Šito es ielieku katra faila sākumā, kur ir vajadzīga lietotāja autorizācija <? if(!isset($_SESSION['logged'])) { header("Location: login.php"); } ?> Edited May 1, 2006 by Jackal Link to comment Share on other sites More sharing options...
v3rb0 Posted May 1, 2006 Report Share Posted May 1, 2006 * sql'aa where pieliec. * session_start() ir? Link to comment Share on other sites More sharing options...
Jackal Posted May 1, 2006 Author Report Share Posted May 1, 2006 (edited) Kad tas session_start() ir jāliek, tur kur ir login forma vai arii tur kur ir php? Un priekškam sqlaa jaliek where? Edited May 1, 2006 by Jackal Link to comment Share on other sites More sharing options...
v3rb0 Posted May 1, 2006 Report Share Posted May 1, 2006 nevajag (es pat teiktu nedrīxt) php pusē tā salīdzināt. select `nickname`,`password` from users where nickname="$nickname" and `password`="$password" visur kur vajag sessiju ar vajag session_start() Link to comment Share on other sites More sharing options...
john.brown Posted May 1, 2006 Report Share Posted May 1, 2006 (edited) katra faila sākumā liec session_start(). Un sql where ir jāliek, lai dabūtu ārā KONKRĒTU user, nevis visus. Nu redz, kamēr rakstīju, jau atbildēja :) Edited May 1, 2006 by john.brown Link to comment Share on other sites More sharing options...
Jackal Posted May 1, 2006 Author Report Share Posted May 1, 2006 Nu viss aizgāja, bet tagad saskāros ar problēmu, ka vajag uztaisīt pogu logout. Laikam te būs kaut kā jāizdzēš uzsāktā sesija vai kā? Kā to uztaisīt? Link to comment Share on other sites More sharing options...
andrisp Posted May 1, 2006 Report Share Posted May 1, 2006 Visvienkāršākais: $_SESSION = array(); Link to comment Share on other sites More sharing options...
john.brown Posted May 1, 2006 Report Share Posted May 1, 2006 session_destroy(); Link to comment Share on other sites More sharing options...
Vebers Posted May 1, 2006 Report Share Posted May 1, 2006 No lv.php.net manuāļa - http://lv2.php.net/session_destroy <?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // If it's desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } // Finally, destroy the session. session_destroy(); ?> Link to comment Share on other sites More sharing options...
andrisp Posted May 1, 2006 Report Share Posted May 1, 2006 Es īstenībā vēl aizvien īsti neesmu sapratis, ko tieši dara session_destroy() fja . Link to comment Share on other sites More sharing options...
john.brown Posted May 1, 2006 Report Share Posted May 1, 2006 (edited) Viņš izdzēš sessijas datus no diska (vai db). tāpēc vēlams pēc session_destroy taisīt redirectu, jo globālais mainīgais $_SESSION saglabājas, tā kā ir ielasīts pirms session_destroy() izsaukuma. Redirecta gadījumā viņu vairs nav no kā ielasīt :) Vai arī, kā manuāļa piemērā augstāk... Edited May 1, 2006 by john.brown Link to comment Share on other sites More sharing options...
Recommended Posts