login with smarty
Posted: Tue Apr 25, 2006 10:41 pm
i wish to do a login system using smarty template engine, so far, i've used my previous version of login page, but cannot do it in smarty...
index2.tpl
index2.php
i know using $smarty->assign() will assign some values from index2.php to index2.tpl, but i really don't know how to make this code work...please help...thanks in advance... 
note: have deleted some smarty syntax for a fresh start
index2.tpl
Code: Select all
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
username: <input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>">
password: <input type="password" name="password">
<input type="submit" name="submit" value="submit">
</form>index2.php
Code: Select all
if (isset($_POST['submit']))
{
$message = null;
//username
if (empty($_POST['username']))
{
$un = false;
$message .= "please type your username";
}
else
{
$un = $_POST['username'];
}
//password
if ($_POST['password'])
{
$pw = false;
$message = 'plese type your password';
}
else
{
$pw = $_POST['password'];
}
//process to username and password to db
if ($un && $pw)
{
$query = "select user_id, username, password from users where username='$un' and password='$pw'";
$result = @mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_NUM);
if ($row)
{
// Start the session, register the values & redirect.
session_start();
$_SESSION['firstname'] = $row[1];
$_SESSION['user_id'] = $row[0];
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
}
else
{
$message .= "username and password do not match";
}
mysql_close();
}
$message = "please try again";
}
if (isset($message))
{
echo "<font color=red>" . $message . "</font>";
}note: have deleted some smarty syntax for a fresh start