Jump to content
php.lv forumi

login skripts


reGative

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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 by briedis
Link to comment
Share on other sites

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 by reiniger
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...