ziedinjsh Posted August 21, 2009 Report Share Posted August 21, 2009 (edited) Sveiki, Šāds ir logina scritps: <?php //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $epasts = $_COOKIE['ID_my_site']; $pass = $_COOKIE['ID_my_site']; $check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['pass']) { } else { header("Location: index.php"); } } } //if the login form is submitted if (isset($_POST['login'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['email'] | !$_POST['pass']) { die('Aizpildi visus lauciņus.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('Šāds producents nav šeit reģistrējies'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['pass'] = stripslashes($info['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['pass']) { die('Nepareiza parole.'); } else { // if login is ok then we add a cookie $_POST['email'] = stripslashes($_POST['email']); $hour = time() + 60 * 60 * 3; setcookie('ID_my_site', $_POST['email'], $hour); setcookie('Key_my_site', $_POST['pass'], $hour); //then redirect them to the members area header("Location: index.php"); } } } else { echo"<form name='login' method='post' action='index.php'>"; echo"<table width='210' border='0' align='center' cellpadding='0' cellspacing='0' class='login'> <tr> <th align='right' scope='col'>e-pasts:</th> <th align='right' scope='col'> <input type='text' name='email' class='ltextbox'></th> </tr> <tr> <th align='right' scope='col'>parole:</th> <th align='right' scope='col'> <input type='password' name='pass' class='ltextbox'> </th> </tr> <tr> <th align='right' scope='col'> </th> <th align='right' scope='col'> <input type='submit' name='login' value='ieiet' class='lbutton'> </th> </tr> </table> "; echo"</form>"; } ?> Kad ielogojas tad vienalga var atvērt login.php scriptu.. lai gan viņam vajadzētu mest uz index.php sanāk tā ka lietotājs ielogojas, bet viņš nav ielogojies.. es īsti nesaprotu būtu vajadzīgs kaut kas tāds: if (user) { header("Location: index.php"); } if (guest) { header ("Location: login.php"); } Kaut kā tā, tikai nezinu kā īsti uztaisit to, jo logina scripts nav manis taisīts Edited August 21, 2009 by ziedinjsh Link to comment Share on other sites More sharing options...
Aleksejs Posted August 21, 2009 Report Share Posted August 21, 2009 Turpini vien iepriekš iesākto: http://php.lv/f/topic/14279-php-login/ Link to comment Share on other sites More sharing options...
Recommended Posts