Jump to content
php.lv forumi

php registracija


Nero

Recommended Posts

Forumā bija kaut kas tāds ->

 

login-form.php

<html>
<head>
<title>Login page</title>
<?php 
session_start();
$_SESSION['rand']=mt_rand(1, 10000);
?>
</head>
<body>
<form action="secure-page.php" method="post">
user:<input name="usr" type="text" /><br />
password:<input name="pwd"  type="password" /><br />
<input name="verify" type="hidden" value="<?php echo $_SESSION['rand']; ?>" />
<input name="ok" type="submit" />
</form>
</body>
</html>

 

secure-page.php

<?php 
ob_start();
session_start();
if ($_COOKIE['auth']=='logged_in' ) {
       echo 'protected page';
}
elseif ($_POST['verify']==$_SESSION['rand']) {
       $connect = mysql_connect("localhost", "root", "") or die("bad connection");
       mysql_select_db("some_database");
       $usr=mysql_real_escape_string($_POST['usr']);
       $pwd=mysql_real_escape_string($_POST['pwd']);
       if ( $usr=='mike' && $pwd=='secret' ) { 
               setcookie('auth','logged_in');
               echo 'protected page';
       }
       else {
               echo 'incorrect credentials ';
       }
}
else { 
               echo 'you are not authorized to view this page!'; 
}
ob_end_flush();
?>

Edited by Martiny
Link to comment
Share on other sites

Piedod Nero, tas tāds s.....s piemērs.

Te būs vēl.

<?php
//include("../config.php");
if(isset($_POST['nick']))
{
		$kludas =array();

if($_POST['parole1'] != $_POST['parole2'])  $kludas[] = 'Paroles nesakrit';
if(strlen($_POST['nick']) <=3 )  $kludas[] = 'Ievaditais Lietotaj vards ir parak iss Minimalas prasibas ir 4 simboli!';
if(strlen($_POST['parole1']) <=6 )  $kludas[] = 'Ievaditais Parole ir parak iss Minimalas prasibas ir 6 simboli!';


 #ja nau kludu
 if(count($kludas) == 0)
	{
			$niks = quote_smart($_POST['nick']);
			$parole = quote_smart(md5($_POST['parole1']));

			$result = mysql_query("SELECT COUNT(*) FROM lietotaji WHERE nick = $niks");
			$rezultats_kopa = mysql_result($result,0,'COUNT(*)');
					 if($rezultats_kopa > 0)
							{
							$kludas[] = 'Sads lietotajs jau eksiste';
							}
						else
							{
							 mysql_query("INSERT INTO lietotaji (nick,parole,tips) VALUES ($niks,$parole,1)");
							  $kludas[] = 'veiksmigi izveidots lietotajs';
							}
	}
foreach($kludas as $kluda)
	{
		echo '<p>'. $kluda .'</p>';
		//echo "$kluda";
	}

}
?>

<form method="post">
<table border="1">
<tr><td>Lietotajvards:</td><td> <input type="text" name="nick" /></td></tr>
<tr><td>parole:</td><td> <input type="password" name="parole1" /></td></tr>
<tr><td>Parole atkartot :</td><td> <input type="password" name="parole2" /></td></tr>
<td><input type="submit" value="submit" /></td>
</table>
</form>

Uz doto brīdi arī es strādāju pie lietotāju reģistrācijas formas un te iepostoju jautājumu par formā ievadīto datu pārbaudi.

Lai veicas!

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...