ặc ặc , ý mình là ko có xài template engine chi cho nhọc công. có thể 1 vài ứng dụng web phức tạp yêu cầu template engine thì xài .
còn ko thì khỏi xài , thêm vấn đề , thêm phức tạp mà hiệu quả ko thêm bao nhiêu. như hồi lâu có cậu kia mở miệng cái là làm web với công nghệ mới smarty mà nói chuyện chả hiểu smarty là cái gì.
include thì đơn giản. tách bạch hầu hết html với php ra thôi.
ví dụ
xem cuối file này .
login.php
PHP Code:
<?php
//set ini
ini_set('session.gc_maxlifetime', 900);
if(!ini_get('session.auto_start')){
session_start();
}
// include file
include ('config.php');
include(LIB_PATH.'mysql.php');
// if the user logged , he can't login again.
if($_SESSION***91;'user_id'***93;){
Header('location: index.php');
}
$database = new mysql($db_config);
if($_POST***91;'submit'***93;){
$email = trim($_POST***91;'email'***93;);
$password = trim($_POST***91;'pass'***93;);
if($email == '' or $password == ''){
$error = 'You forgot to enter your password and your email!';
}else{
//encode the password
$encoded_password = md5(md5($password.REGISTER_SECRET_KEY));
//retrive the data
$query = "select user_id, first_name , last_name , user_level from users where email = '".$email."' and pass = '".$encoded_password."' and active = 'activated'";
$database->setQuery($query);
$user_data = $database->loadAssoc();
//Make sure user was login successful
if(count($user_data)>0){
//register user data into session
$_SESSION***91;'user_id'***93; = $user_data***91;'user_id'***93;;
$_SESSION***91;'first_name'***93; = $user_data***91;'first_name'***93;;
$_SESSION***91;'last_name'***93; = $user_data***91;'last_name'***93;;
$_SESSION***91;'user_level'***93; = $user_data***91;'user_level'***93;;
//check if user click "remember me" then save the cookie.
if($_POST***91;'login_remember'***93; == 1){
setcookie(COOKIE_PRIFIX."logined",true,time()+LOGINED_COOKIE_TIME);
setcookie(COOKIE_PRIFIX."user_id",$user_data***91;'user_id'***93;,time()+LOGINED_COOKIE_TIME);
setcookie(COOKIE_PRIFIX."first_name",$user_data***91;'first_name'***93;,time()+LOGINED_COOKIE_TIME);
setcookie(COOKIE_PRIFIX."last_name",$user_data***91;'last_name'***93;,time()+LOGINED_COOKIE_TIME);
setcookie(COOKIE_PRIFIX."user_level",$user_data***91;'user_level'***93;,time()+LOGINED_COOKIE_TIME);
//echo 11;
}
//checking if the user did not add mission_statement
$query = "select mission_statement from users where user_id = ".$_SESSION***91;'user_id'***93;;
$database->setQuery($query);
$database->query();
//echo $query;
$mission_statement = $database->loadResult();
if($mission_statement == 0){
Header('location: mission.php');
exit;
}
//checking if they're not edit their profile.
$query = "select option_id from options where object_id = ".$_SESSION***91;'user_id'***93;." and name = 'user_profile_display'";
$database->setQuery($query);
$database->query();
if($database->getNumRows()>0){
Header('location: index.php');
}else{
Header('location: edit_profile.php');
}
}else{
$error = 'Either the email address and password entered do not match those on file or you have not yet activated your account.';
}
}
}
//template
include(TEMP_PATH.'login_tpl.php');
?>
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Login</title>
<link href="templates/css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="templates/js/jquery-1.4.4.min.js"></script>
</head>
<body>
<div id="header">
<div id="left-header">
<div id="logo-center">
<img src="templates/images/filmthoslogo1.png" width="311" height="50" />
</div>
</div>
</div>
<div id="body">
<?php include(TEMP_PATH.'main_menu_tpl.php');?>
<div id="content">
<?php if($error !=''){?>
<div class="error"><?php echo $error;?></div>
<?php }?>
<form action="login.php" method="post">
<table>
<tr>
<td style="height: 40px">Email Address</td>
<td><input type="text" name="email" class="form-text-input-short"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" class="form-text-input-short"></td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="login_remember" id="login_remember" value="1"><label for="login_remember">Remember me</label> - <a href="forgot_password.php">Forgot password</a></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Login">
</td>
</tr>
</table>
</form>
</div>
<div class="cleared"></div>
</div>
<div id="footer">
<?php include(TEMP_PATH.'footer_tpl.php');?>
</div>
</body>
</html>
[=========> Bổ sung bài viết <=========]
dấu [ diễn đàn chuyển thành ***91; @@
Bookmarks