Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 15:55

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



PHP template system help

Discussion on PHP template system help within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
mlukac89's Avatar
 
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
PHP template system help

Hi,
I'm working on some cms for gamers and teams, wars, etc...

But i have problem how to separate html from php.
For example i want make all includes so when u make template u just include file in and thats it
Code:
<?php include 'latest_news'; ?>
for example.

Now i have

index.php ( here will be all includes, css, js )
login.php ( here will be checks for user data )
FOLDER named Templates -> login.html

So now i need when i finish all in login.php to call data from html file and in html file just to be variables from login.php

like

Code:
<?php

if (!defined('ACCESS')) {
	die('Forbidden!');
}

if ($general->is_logged() === true) {

	include 'inc/logged.html';
	
} else {

// login form
if (isset($_POST['login']))
{
	$username = $_POST['username'];
	$password = $general->safepass($_POST['password']);
	$last_login_date = time();
	$ip = $general->get_ip();

	if (empty($username) || empty($password))
	{
		$error = $lang['login_error_user'];
	}
	else
	{
		$login = $users->login($username, $password);

		// cookie login
		if (isset($_POST['stay_logged']))
		{
			if ($login) 
			{
				$user_id = $login['id'];

				$expire = time()+60*60*24*30;

				$rand = hash('sha512', mt_rand());

				setcookie('token', $rand, $expire);
				setcookie('username', $login['username'], $expire);
				setcookie('id', $login['id'], $expire);

				$update_login_data = $users->update_cookie_login($last_login_date, $ip, $rand, $user_id);

				header('Location: index.php');
				exit();
			}
			else
			{
				$error = $lang['login_error_data'];
			}
		}

		// session login
		else
		{
			if ($login) 
			{
				$_SESSION['id'] = $login['id'];
				$_SESSION['username'] = $login['username'];
				$user_id = (int)$_SESSION['id'];

				$update_login = $users->update_user_ip_login($last_login_date, $ip, $user_id);

				header('Location: index.php');
				exit();
			}
			else
			{
				$error = $lang['login_error_data'];
			}
		}
	}
}

}

?>
Code:
<form action="" method="POST">
<input type="text" name="username" placeholder="<?php echo $user?>">
<input type="password" name="password" placeholder="<?php echo $pass?>">
<input type="submit" name="login" value="<?php echo $login_button?>">
</form>
mlukac89 is offline  
Old 10/24/2014, 23:04   #2
 
KoKsPfLaNzE's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 731
Received Thanks: 233
you have to write a tempalte engine for that or use smth like twig or smarty. btw the system with seperate html from php is a system like MVC, if you good in PHP you can use a framework, so you dont have to start at zero with the code.
KoKsPfLaNzE is offline  
Old 10/24/2014, 23:14   #3
 
mlukac89's Avatar
 
elite*gold: 0
Join Date: Sep 2010
Posts: 473
Received Thanks: 104
Nah i dont like that template engines and MVC too, but i saw 1 way in one cms itsno so hard its go like this

Code:
// this variables i can use in that template
$forgot_pass = $lang['login_error_forgot_pass'];
$register = $lang['login_error_register'];
$login_btn = $lang['login_error_button'];

// so this part calls template html and shows a form
eval ("\$login = \"".$general->gettemplate("login")."\";");
echo $login;
and this code i use in class

Code:
public function gettemplate($template, $ext='html', $calledfrom='root')
	{
		
		$templatefolder = 'inc';
		
		if ($calledfrom=='root')
		{
			return str_replace("\"", "\\\"", file_get_contents($templatefolder.'/'.$template.'.'.$ext));
		}
		elseif ($calledfrom=='admin')
		{
			return str_replace("\"", "\\\"", file_get_contents('../'.$templatefolder.'/'.$template.'.'.$ext));
		}
	}
but im not sure is there more simple solution and if this is safe one.
mlukac89 is offline  
Reply


Similar Threads Similar Threads
[Release] ETMuS - Simple template system
05/05/2012 - Coding Releases - 2 Replies
+----------+ | English | +----------+ Hi all, I am proud to release my third work now: ETMuS - Extendable Template Markup Script. I will also publish some plugins for this release soon. Those will include a plugin for MySQL and MSSQL database connections. I started this project quite a while ago and was always extending it and adding some features. I hope that this script helps someone out there to create complex sites with a low cost of time building up the base for it. It was...
[Template]Homepage Template by CrystalPrime (Gold-Version)
09/21/2011 - Metin2 PServer Guides & Strategies - 46 Replies
#Done
[PHP] Template System
01/11/2011 - Web Development - 3 Replies
moin moin, Damals als ich im Praktikum war habe ich mit einem anderen Praktikanten ein Templatesystem entwickelt - einfach gehalten! Ich habe vor ner zeit mal die 12 PHP sicherheits regeln gelesen: 2. Regel: In ein include() gehören keine REQUEST-Variablen. und nun wirfts mir die frage auf: kann ich des system ohne bedenken einsetzen? gibts da sicherheits lücken? hier der code:



All times are GMT +2. The time now is 15:55.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.