nemec Posted September 16, 2005 Report Share Posted September 16, 2005 <? include "../funk/func.php"; include "../inc/db.inc"; $iple=$_SERVER['SERVER_ADDR']; $ip=$_SERVER['REMOTE_ADDR']; $arg=" "; session_start(); if (isset($_GET['log'])){$kods=NULL; session_unregister("kods"); session_destroy(); header("Location: index.php");} if (isset($_POST['submit'])){$email1=por($_POST['email']);$pass1=por($_POST['pass']); if (mysql_num_rows(mysql_query("select id from users where email='$email1' and pass='$pass1'"))== 1){ $kods = md5(mt_rand(0, mt_getrandmax())); $beiguda= time() + 900; $_SESSION["kods"]=$kods; $result = mysql_query("select id from users where email='$email1' and pass='$pass1'"); $di= mysql_fetch_array($result); mysql_free_result($result); mysql_query("DELETE FROM user_sess WHERE laiks+604800 < 'time()'"); mysql_query("insert into user_sess (id,ip,iple,laiks,userid) values ('$kods','$ip','$iple','$beiguda','$di[0]')"); unset($di); } else {$arg="nepareiza parole vai epasts";} } if (isset($_SESSION["kods"])){$kods=$_SESSION["kods"];} else {$kods = "iikuud";} if (mysql_num_rows(mysql_query("select userid from user_sess where id='$kods' and ip = '$ip' and iple = '$iple' and laiks > 'time()'"))== 1){ $beiguda= time() + 900; mysql_query("UPDATE user_sess set laiks = '$beiguda' WHERE id = '$kods' and ip = '$ip' and iple = '$iple'"); $result=mysql_query("select userid from user_sess where id='$kods' and ip = '$ip' and iple = '$iple' and laiks > 'time()'"); $di= mysql_fetch_array($result); $id=$di[0]; mysql_free_result($result); unset($di); include "main.php"; } else { ?> <html> <head> <title>pedagogi</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1257" /> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <table align="center"><tr><td height="100"> </td></tr> <tr><td align="center"> <?=$arg?></td></tr> <tr><td> <form action="?" method="post"> <table cellspacing="0"><tr><td align="right">email:</td><td><input type="text" name="email"></td></tr> <tr><td align="right">pass:</td><td><input type="password" name="pass"></td></tr> <tr><td colspan="2" align="center"><input type="submit" name="submit" value="ieiet"></td</tr> </table> </form> </td></tr> </table> </body> </html> <?} mysql_close($connection);?> func.php tur tikai viena funkcija, kura taisa mainiigajam trim() un htmlspecialchars; vai es pareizi izmantoju sessijas??? taadu skriptu viegli lauzt, sakiet caurumus... taads variants ar sessijaam straadaas wapaaa, ja lietotaaju buus pachka? Link to comment Share on other sites More sharing options...
Delfins Posted September 16, 2005 Report Share Posted September 16, 2005 ak dies.. Skriptu rakstīt māki, a pats pārbaudīt nevari? Link to comment Share on other sites More sharing options...
Kavacky Posted September 16, 2005 Report Share Posted September 16, 2005 http://paste.php.lv/ Link to comment Share on other sites More sharing options...
v3rb0 Posted September 16, 2005 Report Share Posted September 16, 2005 sitais blaakis tak vienreiz bija, es veel tur pie visa kaa pieseejos.. Link to comment Share on other sites More sharing options...
nemec Posted September 16, 2005 Author Report Share Posted September 16, 2005 nu jaa bija, bet iepriekšējais bija ar kukijiem un drusku caurumains pēc jūsu domām. es vēl speciāli mēģināju normāli noformēt kodu, a kas tik briesmīgi es rakstu, man visi tādi...;] Link to comment Share on other sites More sharing options...
nemec Posted September 16, 2005 Author Report Share Posted September 16, 2005 http://paste.php.lv/2513 nu vot kods strādā, ja kas. specu viedokļi interesē. es salasījos monuālus par 2002 gadu un esu drusku atpalicis no jums.... Link to comment Share on other sites More sharing options...
Kaklz Posted September 16, 2005 Report Share Posted September 16, 2005 http://paste.php.lv/2513 nu votkods strādā, ja kas. specu viedokļi interesē. es salasījos monuālus par 2002 gadu un esu drusku atpalicis no jums.... 22393[/snapback] Es tev ieteiktu palasīt kaut ko par PHP Coding standards, jeb to, kā noformēt uzrakstīto PHP kodu, lai tas būtu ērtāk lasāms un labāk uztverams. Ja tu turpināsi visu rakstīt šādā blāķī, tad es turpināšu tavu kodu nelasīt (pilnīgi pieļauju domu, ka tā dara un darīs arī citi). Link to comment Share on other sites More sharing options...
nemec Posted September 16, 2005 Author Report Share Posted September 16, 2005 nu tu piedod, bet tev grūti izlasīt 30 rindiņas. nu es ņemšu vērā tavējo ieteikumu, ja kas neesmu iestindzis uz vietas.. Link to comment Share on other sites More sharing options...
bubu Posted September 16, 2005 Report Share Posted September 16, 2005 Nu gluži kā BlachHalt stils. Viņš tavus kodus noteikti izlasītu. Link to comment Share on other sites More sharing options...
Delfins Posted September 17, 2005 Report Share Posted September 17, 2005 neviena TAB... tādu vloms lasīt pat pirmo rindu :) Link to comment Share on other sites More sharing options...
nemec Posted September 17, 2005 Author Report Share Posted September 17, 2005 NU A TAGAD http://paste.php.lv/2515 patiik???? Link to comment Share on other sites More sharing options...
Kavacky Posted September 17, 2005 Report Share Posted September 17, 2005 Vēl ne: else {$arg="nepareiza parole vai epasts";} -> else { $arg="nepareiza parole vai epasts"; } Link to comment Share on other sites More sharing options...
Lynx Posted September 17, 2005 Report Share Posted September 17, 2005 Viena no uzreiz acīs krītošām problēmam, ir ka "" tiek lietots pilnīgi nevietā, kur nav paredzēti mainīgie. Lai uzlabotu koda izplides ātrumu vajadzētu būt šādi: include('../funk/func.php'); $arg = ' '; $arg = 'nepareiza parole vai epasts'; header('Location: index.php'); etc, domu saprati. Neieteiktu šādi rīkoties: $result=mysql_query("select userid from user_sess where id='$kods' and ip = '$ip' and iple = '$iple' and laiks > 'time()'"); $di= mysql_fetch_array($result); $id=$di[0]; mysql_free_result($result); unset($di); Es darītu šādi, ja ir nepieciešams izvilkt tikai vienu lauku no tabulas: list($id) = mysql_fetch_row(mysql_query('SELECT userid FROM user_sess WHERE id ="'.$kods.'" AND ip = "'.$ip.'" AND iple = "'.$iple.'" AND laiks > time() ')); Tāpat mysql_num_rows vietā labāk lietot SELECT COUNT(*) WHERE būs ātrāk. Link to comment Share on other sites More sharing options...
Kavacky Posted September 17, 2005 Report Share Posted September 17, 2005 Tāpat mysql_num_rows vietā labāk lietot SELECT COUNT(*) WHERE būs ātrāk.Nav labāk lietot SELECT COUNT(`id`), lai netērētu lieki resursus? Link to comment Share on other sites More sharing options...
Analgiins Posted September 19, 2005 Report Share Posted September 19, 2005 taa starp citu par SELECT COUNT(*) vai COUNT('id') - kas buus, ja vaicaajumaabuus HAVING klause ? Link to comment Share on other sites More sharing options...
Recommended Posts