Jump to content
php.lv forumi

4ortavas sesijas


Snukzz

Recommended Posts

Ir kods kursh neiet:

<?php
include('config.php');
include($CONF['inc_A'].'connect.php');
?>
<TABLE cellpadding=0 cellspacing=0 align="CENTER" valign="CENTER" width="200" border="1" borderstyle="SOLID" bgcolor="#CCCCCC">
<FORM action=do_login.php method=post id=f>
 <TR><TD colspan=2 align="CENTER"><font face="ARIAL" size="2" color="#00099"><b>      LOGIN TO ILB</b></font></TD></TR>
 <TR><TD><font face="ARIAL" size="1" color="#FF0000"><b>NAME:</b></font></TD><TD align="CENTER"><INPUT type=text name=name value="<?=$_SESSION['name'] ?>" id=n></TD></TR>
 <TR><TD><font face="ARIAL" size="1" color="#FF0000"><b>PASW:</b></font></TD><TD align="CENTER"><INPUT type=password name=psw value="<?=$_SESSION['passw'] ?>" id=p></TD></TR>
 <TR><TD> </TD><TD align="CENTER"><INPUT type=submit value="ENTER ILB"></TD></TR>
</FORM>
</TABLE>

Esmu varbuut veel aizmidzis, bet nerubiiju, kur ir kljuuda. Piekonnektee visu OK, bet bljauj par nedefineetu "name" :ph34r: kaa vinsh ir jaadefinee? Kaa sesijas nosaukums, vai kaa...??? :blink:

Link to comment
Share on other sites

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

pēc noklusējuma sessija ir tukšs masīvs, tāpēc, ja tu raksti uzreiz

$_SESSION['name'] => name apakšelements nav definēts

var rīkoties divejādi

 

- iniciēt mainīgo ar noklusēto vērtību

if (empty($_SESSION['name'])) (vai tikai !isst($_SESSION['name']))

$_SESSION['name']='';

 

pārbaudīt tieši pie izvada

echo '<input name="x" value="'.(empty($_SESSION['name'])?'':$_SESSION['name']).'" />';

Link to comment
Share on other sites

:rolleyes:

vaardu sakot rekur mans varianc:

pas skripc kursh tipa ielogo

<?
error_reporting(E_ALL);
include('config.php');

$error=0;
if(!isset($_POST['name']) || $_POST['name']==''){
$error=1;
$_SESSION['logerror'][]='ieraksti vārdu';
}
if(!isset($_POST['passw']) || $_POST['passw'] || $_POST['passw']==''){
$error=1;
$_SESSION['logerror'][]='ieraksti paroli';
}
if($error!=1){
$res=mysql_query('SELECT id,name FROM users WHERE name=\''.user_texc($_POST['name'],$CONF['max_nik'],255,1,1).'\'))=\''.user_texc($_POST['psw'],33,255,1,1).'\'');
if($row=mysql_fetch_row($res)){
 $_SESSION['id']=$row[0];
 $_SESSION['name']=$row[1];
 
}else{
 $res=mysql_query('SELECT id,name FROM users WHERE name=\''.user_texc($_POST['name'],$CONF['max_nik'],255,1,1).'\' && psw=\''.user_texc($_POST['psw'],33,255,1,1).'\'');
 if($row=mysql_fetch_row($res)){
  $_SESSION['id']=$row[0];
  $_SESSION['name']=$row[1];

 }else{
  $_SESSION['logerror'][]='Nepareiza parole vai lietotāja vārds';
 }
}
}
if ($logerror=1){?>
<TABLE align="center">
<TR><TD> </TD><TD><?
if(isset($_SESSION['logerror'])){
?><P class=logerror><?
while(list($key,$val)=each($_SESSION['logerror'])){
?><?=$key+1 ?>) <?=$val ?><BR><?
}
?></P><?
unset($_SESSION['logerror']);
}
?></TD></TR>
</TABLE>
<?}
else{ header("Location: $CONF[inc_A]logged.php");}
?>

Link to comment
Share on other sites

KLAU!!! SHADI eroru neizmet tikai nepaarsuuta passw..:(

<?php
include('config.php');
include($CONF['inc_A'].'connect.php');
session_register('passw','name');
{
?>
<TABLE cellpadding=0 cellspacing=0 align="CENTER" valign="CENTER" width="200" border="1" borderstyle="SOLID" bgcolor="#CCCCCC">
<FORM action=do_login.php method=post id=f>
 <TR><TD colspan=2 align="CENTER"><font face="ARIAL" size="2" color="#00099"><b>      LOGIN TO ILB</b></font></TD></TR>
 <TR><TD><font face="ARIAL" size="1" color="#FF0000"><b>NAME:</b></font></TD><TD align="CENTER"><INPUT type=text name=name value="<?=$_SESSION['name'] ?>" id=n></TD></TR>
 <TR><TD><font face="ARIAL" size="1" color="#FF0000"><b>PASW:</b></font></TD><TD align="CENTER"><INPUT type=password name=psw value="<?=$_SESSION['passw'] ?>" id=p></TD></TR>
 <TR><TD> </TD><TD align="CENTER"><INPUT type=submit value="ENTER ILB"></TD></TR>
</FORM>
</TABLE>
<?}?>

Link to comment
Share on other sites

KLAU!!! SHADI eroru neizmet tikai nepaarsuuta passw..:(

<?php
...
session_register('passw','name');
...
<FORM action=do_login.php method=post id=f>
...

Tev passw un name ir globāli mainīgie?

Gadījumā pirms session_register nevajag:

$passw = $_POST['psw'];
$name = $_POST['name'];

jo metode ta formai ir post, un diezvai tev ir automātiski globāļu piereģistrācija ieslēgta?

Edited by bubu
Link to comment
Share on other sites


×
×
  • Create New...