Jump to content
php.lv forumi

Login


toms42

Recommended Posts

Sveiki, nu tad beidzot iesāku, ko vēlejos, prezicāk sakot macīties php valodu ^^

Protams izvelejos macities tieši tā pat ka css un html, nelasot nekadus suņa murgus vnk veidojot kkadu projektu!

Taka ceru nedusmosietis bet mani šeit sastapsiet bieži ar dažādiem muļķīgiem jautajumiem!

 

Tā tad 1. problēma!

 

Es izveidoju registraciju ar login

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
require_once("connect.php");

// Check if he has the right info.
$query = mysql_query("SELECT * FROM users
						WHERE username = '$_POST[username]'
						AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");

$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");

if (!empty($row[username])) // he got it.
{
$a = mysql_fetch_assoc(mysql_query("SELECT * FROM users"));
 $_SESSION[username] = $row[username];
 echo "Sveiks $_POST[username] ".$a['ip']." ! You've been successfully logged in.";
 exit();

}
else // bad info.
{
	echo "Error - Couldn't login user.<br /><br />
		Please try again.";
	exit();
}
}

?>

 

<div id="login">

<form action="login.php" method="post" class="login">
   <fieldset>
       <legend>Autorizācija</legend>
	<label>Lietotajvards</label><br />
       <input type="text" name="username" value="<? echo $_POST[username]; ?>" class="username" /><br />
       <p class="username_error" style="margin: 0; display: none;">That Username is unavailable</p>

	<label>Parole</label><br />
       <input type="password" name="password" value="" /><br />

       <input type="submit" name="submit" value="Ienakt" />  <u>Registreties</u>
   </fieldset>
</form>
</div>

 

 

Kā panākt, lai pec autorizācijas apstiprināšanas viņš nevis iemet login.php lapā, bet gan paliek index.php un login vieta nolasa lietotaja datus?

Link to comment
Share on other sites

pāradresācija

echo "Sveiks $_POST[username] ".$a['ip']." ! You've been successfully logged in.";

Šī vietā liec

header("Location: index.php");

un parādīs index.php

 

pie tam

"Sveiks $_POST[username] "; fragments nevar strādāt, nepareiza sintakse

vai nu

"Sveiks ".$_POST['username'];

vai

"Sveiks {$_POST['username']}";

Edited by mickys
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...