reGative Posted July 11, 2011 Report Share Posted July 11, 2011 sveiki. Kad jūzeris ielogojas, gribu, lai parādās visa informācija par viņu. skripts ir šāds. <?php $query = mysql_query("SELECT user_nick FROM users where user_id='$_SESSION[id]'"); echo $query;?> . 'reGative' vietā parāda 'Resource id #4'. Kāpēc tāds uzraksts parādās? Jā zinu, ka kods nav pareizs, jo tad rādītu pareizi. Quote Link to comment Share on other sites More sharing options...
briedis Posted July 11, 2011 Report Share Posted July 11, 2011 Ko lai te saka kā tikai... RTFM (ieskaitot komentārus). http://php.net/manual/en/function.mysql-query.php Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted July 11, 2011 Report Share Posted July 11, 2011 A kas notiek, ja es atveru Tavu lapu šādi: www.tavalapa.lv/index.php?PHPSESSIONID=1%20or%201=1 Quote Link to comment Share on other sites More sharing options...
reGative Posted July 11, 2011 Author Report Share Posted July 11, 2011 Palaboju kodu <?php $yoo = mysql_query("SELECT user_nick FROM users WHERE user_id='$_SESSION[id]'") or die(mysql_error()); echo mysql_fetch_array($yoo);?> un tagad 'Resource id #4' vietā nerādās nekas. Quote Link to comment Share on other sites More sharing options...
briedis Posted July 11, 2011 Report Share Posted July 11, 2011 Palaboju kodu <?php $yoo = mysql_query("SELECT user_nick FROM users WHERE user_id='$_SESSION[id]'") or die(mysql_error()); echo mysql_fetch_array($yoo);?> un tagad 'Resource id #4' vietā nerādās nekas. Pārlasi to linku, ko iedevu :) ..un vispār, esi pārliecināts, ka $_SESSION['id'] kaut ko satur? Quote Link to comment Share on other sites More sharing options...
reGative Posted July 11, 2011 Author Report Share Posted July 11, 2011 Paskatījos... uzliku echo $_SESSION['id'];, rāda nulli, kaut arī tam būtu jārāda 1, nevis 0. Logn skripts - if(isset($_GET['f']) and $_GET['f'] == 'l') { $nick = $_POST['nick']; $pass = $_POST['pass']; $query1 = mysql_query("select user_id from users where user_nick='$_POST[nick]'") or die(mysql_error()); $_SESSION['id'] = $query1;?> <script type="text/javascript"> window.location = "mansurl" </script><?php } Quote Link to comment Share on other sites More sharing options...
briedis Posted July 11, 2011 Report Share Posted July 11, 2011 (edited) Nu wadafaaak... Tak sāc ar kādas pamācības izstudēšanu un centies izprast, kas vispār tur notiek... $query1 = mysql_query("select user_id from users where user_nick='$_POST[nick]'") or die(mysql_error()); $_SESSION['id'] = $query1; ..nu kaut vai šo izlasi: http://www.tizag.com/mysqlTutorial/mysqlselect.php Edited July 11, 2011 by briedis Quote Link to comment Share on other sites More sharing options...
reiniger Posted July 11, 2011 Report Share Posted July 11, 2011 (edited) Varbūt tagad strādās... if(isset($_GET['f']) and $_GET['f'] == 'l') { $nick = htmlspecialchars($_POST['nick']); $pass = $_POST['pass']; $result= mysql_query("select user_id from users where user_nick='$nick'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $_SESSION['id'] = $row['id']; } ?> <script type="text/javascript"> window.location = "mansurl" </script><?php } .... Bet vēl ieteikumi paroli kaut vai ar MD5, jau pie saglabāšanas izmantot $pass = md5($_POST['pass']); un tad savukārt query ar paroles pārbaudi arī "select user_id from users where user_nick='$nick' and user_pass = '$pass'" Un pirms javascript izpildes uzliec parbaudi vai atgrieza ID no datu bāzes if(isset($_SESSION['id']){ ?> <script type="text/javascript"> window.location = "mansurl" </script><?php } Edited July 11, 2011 by reiniger Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 11, 2011 Report Share Posted July 11, 2011 Sliktākajā gadījumā "debug'o" ar... var_dump($id); Quote Link to comment Share on other sites More sharing options...
rebuilder Posted July 11, 2011 Report Share Posted July 11, 2011 $result= mysql_query("select user_id from users where user_nick='$nick'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $_SESSION['id'] = $row['id']; } Kādā sakarā while? parasti niks ir unikāls, vai tad nē? Quote Link to comment Share on other sites More sharing options...
reGative Posted July 14, 2011 Author Report Share Posted July 14, 2011 login skriptu un to visu tiku galā, bet tagad ir problēma ar JS redirektiem. <?php if(isset($_REQUEST['logout'])) { session_destroy(); ?><script type='text/javascript'>windows.location = 'mansurl'</script><?php } if(isSet($_REQUEST['login'])) { $user_nick = mysql_real_escape_string($_POST['nick']); $user_password = mysql_real_escape_string($_POST['pass']); $query = mysql_query(" SELECT user_nick FROM users WHERE user_nick = '$user_nick' AND user_password = '$user_password' ") or die(mysql_error()); $total = mysql_num_rows($query); If($total > 0) { session_start(); $_SESSION['user_nick'] = $user_nick; ?><script type='text/javascript'> windows.location = 'mansurl'</script><?php } else { echo 'Pashol ti na **j'; } } ?> login skriptā ielogojas bet adreses lauciņā paliek ?login. Ar logout skriptu ir jāpārlādē pašam, lai parādītos login forma. Vēl kaut kad strādāja, tagad vairs ne. Kas par vainu? Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted July 14, 2011 Report Share Posted July 14, 2011 Kāpēc tev redirekti vispār ir ar js? Quote Link to comment Share on other sites More sharing options...
reGative Posted July 14, 2011 Author Report Share Posted July 14, 2011 tāpēc, ka PHP header("location:mansurl"); nevar ielikt, rāda, ka Warning: Cannot modify header information - headers already sent Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted July 14, 2011 Report Share Posted July 14, 2011 Tad jau šis arī tev nestrādās - session_start(); Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 14, 2011 Report Share Posted July 14, 2011 tāpēc, ka PHP header("location:mansurl"); nevar ielikt, rāda, ka Warning: Cannot modify header information - headers already sent Tāpēc ir jātaisa ar JScript'u? Heh. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.