Jump to content

stumped


ShoeLace1291

Recommended Posts

Ok, I'm trying to set up my index page.  The problem is that nothing is being displayed and I have no idea why.  I have the index page, and a functions page.  There's a function that sets up the template and switches variables so no php is required in the template files.  Here's my index page.  No errors come up, just a blank page.

 

Index.php

<?php

require('config.php');

include('functions.php');

session_start();

//If the user is logged in...
if($_SESSION['accnt_name'] && $_SESSION['accnt_pass']){

$member = array(
		  		'name' => $_SESSION['accnt_name'],
				'pass' => $_SESSION['accnt_name']
				);
$membername = $member['name'];
$memberpass = $member['pass'];

//Make sure the user is actually registered and is logged in with the correct pass
	verifyUser($membername, $memberpass);

//If they aren't registered or logged in with an incorrect pass, log them out and redirect them.
if(!$member_is_valid){

 session_destroy();

  header("Location: index.php");
  
  } else {
  
  	getPerm($membername);

}

} else {

  $userPerm = 0;
  
}
	//If the user is a regular member, set the template for regular members.
	if($userPerm > 1){

	$temps = array(
		   	 	   'WELCOME' => 'Welcome back, ', $member['name'], '.'
				   );

		$templateFile = "template/overall_header_user.tpl";

	}

	//If the user is an admin, set the admin template.
	if($userPerm == 1){

	$temps = array(
		   	 	   'WELCOME' => 'Welcome back, ', $member['name'], '.',
				   'ADMIN_LINK' => "<a href='admin/index.php' target='new'>Admin Panel</a>"
				   );
				   
			$templateFile = "template/overall_header_admin.tpl";

	}

	//If the user is a guest, set the guest template.
	if($userPerm == 0){

	$temps = array(
		   	 	   'WELCOME' => "Welcome, Guest.",
				   'REGISTER' => "<a href='index.php?act=reg'>Register</a>"
				   );
				   
		$templateFile = "template/overall_header_guest.tpl";

	}

	//Put it all together, and we have the header file.
	$header = buildTemplate($templateFile, $temps);

	echo $header;

?>

 

functions.php

<?php

//functions.php

function buildTemplate($templateFile, $temps){

   $buildtemplate = file_get_contents($file);

      foreach($temps as $template_var => $replacement_var){

         $buildtemplate = str_replace($template_var, $replacement_var, $buildtemplate);

         }

       echo $buildtemplate;	   
   
}

function verifyUser($membername, $memberpass){

$query = "SELECT * FROM ib_members WHERE memberName = '$membername'";

	$execute = mysql_query($query) or die(mysql_error());
	   
$exists = mysql_num_rows($execute);

		if($exists == 0) $member_exists = false;

		else $member_exists = true;

	if($member_exists) verifyPass($membername, $memberpass);

	if($member_exists && $pass_correct) $member_is_valid = true;

	else $member_is_valid = false;

}

function verifyPass($membername, $memberpass){

$query = "SELECT * FROM ib_members WHERE memberName = '$membername'";

	   $execute = mysql_query($query) or die(mysql_error());
	   
	 while($grab=mysql_fetch_array($execute)){

	 		$correct_pass=$grab["memberPass"];

	}

	if($member['pass'] != $correct_pass) $pass_correct = false;

	else $pass_correct = true;

} 

function getPerm($membername){

	 $query = "SELECT * FROM ib_members WHERE memberName = '$membername'";

	 		$execute = mysql_query($query) or die(mysql_error());

	while($grab=mysql_fetch_array($execute)){

			$userPerm=$grab["memberPerm"];

	}

}


?>

 

Any help would be great.

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/88854-stumped/
Share on other sites

Try this :

 

 <?php

require('config.php');

include('functions.php');

session_start();

//If the user is logged in...
if($_SESSION['accnt_name'] && $_SESSION['accnt_pass']){

$member = array(
		  		'name' => $_SESSION['accnt_name'],
				'pass' => $_SESSION['accnt_name']
				);
$membername = $member['name'];
$memberpass = $member['pass'];

//Make sure the user is actually registered and is logged in with the correct pass
	verifyUser($membername, $memberpass);

//If they aren't registered or logged in with an incorrect pass, log them out and redirect them.
if(!$member_is_valid){

 session_destroy();

  header("Location: index.php");
  
  } else {
  
  	getPerm($membername);

// removed a } from here.

} else {

  $userPerm = 0;
  
}
	//If the user is a regular member, set the template for regular members.
	if($userPerm > 1){

	$temps = array(
		   	 	   'WELCOME' => 'Welcome back, ', $member['name'], '.'
				   );

		$templateFile = "template/overall_header_user.tpl";

	}

	//If the user is an admin, set the admin template.
	if($userPerm == 1){

	$temps = array(
		   	 	   'WELCOME' => 'Welcome back, ', $member['name'], '.',
				   'ADMIN_LINK' => "<a href='admin/index.php' target='new'>Admin Panel</a>"
				   );
				   
			$templateFile = "template/overall_header_admin.tpl";

	}

	//If the user is a guest, set the guest template.
	if($userPerm == 0){

	$temps = array(
		   	 	   'WELCOME' => "Welcome, Guest.",
				   'REGISTER' => "<a href='index.php?act=reg'>Register</a>"
				   );
				   
		$templateFile = "template/overall_header_guest.tpl";

	}

	//Put it all together, and we have the header file.
	$header = buildTemplate($templateFile, $temps);

	echo $header;

?>

Link to comment
https://forums.phpfreaks.com/topic/88854-stumped/#findComment-455188
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.