Jump to content

Using A Template System In Php


bigjoe11a

Recommended Posts

Ok, here I go again. Here's the link if you wanted to take a look. You can log in as admin and pw as adminAs you login you will see on the right side of the page. it shows you as log in. well is you look on the left side of the page it doesn't see the sessions I guess. I'm not sure why this doesn't work. Here comes the code.This is in the index.php. I use a template to load 3 pages in.

 //Top Status Block$page = new page('styles/templates/topstatus.html');$page->replace_tags(array('PROFILE'		=> 'styles/templates/profile.php','STATUS'		 => 'styles/templates/status.php','LOGIN'		  => 'sources/login.php',));$page->output();

The page in the center. Just returns info from a class and it works just fine. The one one the end show a login page and well that code is below...

<?phpinclude 'sources/class.login.php'; if(isset($_POST['login'])){  $login = new Login();  if($login->isLoggedIn()) {		echo 'Loggin Successfull<br />';  		$user['loggedin'] = true;  //define('LOG_IN', true);	  		define('LOGGED_IN', true);      } else {		$login->showErrors();	    }   unset($_POST['login']);}if(!isset($_SESSION[SESS_USER]) && !isset($_SESSION[SESS_EMAIL])) {  $token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));?><form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"><table><tr><td>Username:</td><td><input type="text" name="username" /></td></tr><tr><td>Password:</td><td><input type="password" name="password" /></td></tr></table><input type="hidden" name="token" value="<?php echo $token;?>" /><input type="submit" name="login" value="Log In" /></form><?php} else {   echo 'Welcome Back '. $_SESSION[SESS_USER].'<br />';   echo '<a href="sources/logout.php">Log out</a><br />';}?> 

and last the profile.php code.

 <?phpif(isset($_SESSION[SESS_USER])) {  	$name = $_SESSION[SESS_USER];	$email = $_SESSION[SESS_EMAIL];	$member = $_SESSION[SESS_MEMBER];	$userid = $_SESSION[SESS_USERID];	$uid = $_SESSION[SESS_USERID];	$welcome = "Profile Name : " . $name . "";	$membership = "Membership Status : ".$member."";  	$list = DataManager::GetProfile();  	if(count($list))	{		foreach($list as $row)		list($avatar,$age,$birthdate) = @array_values($row);	  		$_SESSION[SESS_AVATAR] = $avatar;		$_SESSION[SESS_AGE] = $age;		$_SESSION[SESS_BIRTH] = $birthdate;		$avaterImage = $avatar;					  	}    } else {	$welcome = "Profile Name : Guest ";	$membership = "Membership Status : Guest";	$uid = 0;	$avaterImage = "default.png";}//echo "<img src='images/avatar/default.png'";echo 'Your current Profile';?><center><table border="0" style="font-size: 9px;"><tr><tr><td> | <?php echo $uid; ?> | <?php echo $welcome; ?></td></tr><tr><td><?php echo $membership; ?></td></tr><tr><td style="width: 50;height: 50"><img src="images/avatar/<?php echo $avaterImage; ?>" style="height: 50;width: 50;"> <center> <a href="sources/edit_profile.php">Edit Profile</a></center></td></tr></tr></table></center> 

See when you log in, the login page see you as logged in, how ever I can't get the profile page to see the sessions (I Think That's what's wrong) and I don't know why. The profile.php loads profile information in and displays it on the page. any way here's the link for the web site and guys. Don't worry. There's no admin section yet. After you log in the narbar should change too and that's the last item and the code is blow.

 //Top nav barif($user['is_admin'] && defined('LOGGED_IN')) {$page = new page('styles/templates/topnav.html');$page->replace_tags(array('ACP'		=> '<a href="admin.php">Admin Control Panel</a>',	'NAV1'	   => '<a href="'.$linksmain['Home'].'">Home</a>',	  'NAV2'	   => '<a href="'.$linksmain['Game Categories'].'">Game Categories</a>','NAV3'	   => '<a href="'.$linksmain['Blog'].'">Blog</a>','NAV4'	   => '<a href="'.$linksmain['Support Tickets'].'">Support Tickets</a>',	'NAV5'	   => '<a href="'.$linksmain['Articles'].'">Articles</a>',	'NAV6'	   => '<a href="'.$linksmain['User CP'].'">User CP</a>',	'NAV7'	   => '',	'NAV8'	   => '',	'TODAYIS'	=>  $settings['php_date'],	'TIMEIS'	 =>  $settings['php_time'],));$page->output();  } else if(defined('LOGGED_IN')) { //$setting['php_time']$page = new page('styles/templates/topnav.html');$page->replace_tags(array('ACP'		=> '<a href="usercp.php">User Control Panel</a>','NAV1'	   => '<a href="'.$linksmain['Home'].'">Home</a>','NAV2'	   => '<a href="'.$linksmain['Support Tickets'].'">Support Tickets</a>','NAV3'	   => '<a href="'.$linksmain['Blog'].'">Blog</a>','NAV4'	   => '<a href="'.$linksmain['User CP'].'">User CP</a>',	'NAV5'	   => '<a href="'.$linksmain['Articles'].'">Articles</a>',	'NAV6'	   => '<a href="'.$linksmain['Game Categories'].'">Game Categories</a>',	'NAV7'	   => '',	'NAV8'	   => '',	'TODAYIS'	=> $settings['php_date'],	'TIMEIS'	 => $settings['php_time'],));$page->output();} else {$page = new page('styles/templates/topnav.html');$page->replace_tags(array('ACP'		=> '','NAV1'	   => '<a href="'.$linksmain['Home'].'">Home</a>','NAV2'	   => '<a href="'.$linksmain['Register'].'">Register</a>','NAV3'	   => '','NAV4'	   => '',	'NAV5'	   => '',	'NAV6'	   => '',	'NAV7'	   => '',	'NAV8'	   => '',	'TODAYIS'	=> $settings['php_date'],	'TIMEIS'	 => $settings['php_time'],));$page->output();}

and the very last thing is the class that gets the users profile and it's below.

public static function GetProfile()	{	  		self::_DbConnect();	  		$profile = mysql_query("SELECT avatar,age,birthdate FROM ".db_prefix."profiles WHERE uid=".$_SESSION[SESS_USERID]." LIMIT = 1");	  		$row = mysql_fetch_assoc($profile);			$list[] = $row;		  		return $list;	}

Thanks again and I hope I explaint this right and gave better details. Sorry guys. I just don't know of any other way to explain this. Joe http://toppersbbs.dtdns.net/mapnet/

Link to comment
Share on other sites

For some reason the php session code and the code in the action of the attribute is being treated as text, if you view source you will see

		<div class="block_right_content"><?phpsession_start();$token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));?><form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">

also the session_start(); should usually be placed at the top of the page before any code that produces an output.

Link to comment
Share on other sites

Ok, but your talking about the login.php. I'm talking about the profile.php. and on the top of my index.php page. I have a config.php. and that file conatins the session_start(); at the top. So the sessions are started every time a page loads. How ever if I try and load the config.php into the profile.php or the login.php. It says it not needed because a session has already been started,. Your saying that some thing in the login.php file isn't working right. or is being treated as a text object. So how would I go about fixing this. So will this fix the problem in the profile.php file. Joe

Link to comment
Share on other sites

Since you should always check if the user is logged in, you might as well move the session_start() to index.php, and remove it from all other places.As for fixing the text output... you might want to move that PHP code outside of the template. The whole idea of a templating system is for it to NOT use PHP code, but just link to arbitrary data that was generated by PHP.BTW, there's also some notice screwing up your page. You might want to track that down too. Even if itsn't not related, it would still help to clean up things.

Link to comment
Share on other sites

Can you tell me what notice. I don't see any thing wrong, can you send me a screen shot of what your seeing. Joe

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...