Here is what my page is suppose to look like.

There are clickable tabs at the top namely: Home, About, Contact Us.

When I click on the About tab for example, the content for the About would be displayed. However, the content for the Home tab is still there. I want it to not appear anymore. How can I make this work? Here are my codes:

index.php

<html>

<head>
<?php echo "<link rel=\"shortcut icon\" href=\"images/titlebar.png\" />"; ?>
<?php echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"CSS/index.css\" />"; ?>
<title>Some Text Here</title>
</head>

<body>
<div id="container1">
	<?php include("includes/header.php"); ?>
	<div id="container2">
		<?php include("includes/login.php"); ?>					
		<?php include("includes/content.php"); ?><br><br><br><br>		
		<?php include("includes/footer.php"); ?>
	</div>	
</div>
</body>

</html>

header.php

<div id="header">
	<div id="head1">
		<img src="images/header.jpg" height="100px">
		<div id="head2">
		Some Text Here
		</div>	
	</div>	
	<?php include("includes/pagenavigation.php"); ?>	
</div>

pagenavigation.php

<div id="navigation"><b>
	<ul>
		<li><a href="?home=true">Home</a></li>
		<li><a href="?about=true">About</a></li>
		<li><a href="?contactus=true">Contact Us</a></li>
	</ul>
</b></div>

content.php

<div>
	<div id="middlecontainer">
		<h3>Featured</h3>		
		<div id="info1">
			Some Text Here
		</div>
		<div id="info2">
			Some Text Here		
		</div>
	</div>
	<div id="rightcontainer">
		<h1>Welcome</h1>
		<p>Some Text Here for the Main page which is the Home tab.</p>		
	</div>
</div>

Also, there is a login form here. For example, when I have successfully logged in, I want the text on top of the form "Login Area" to be changed to "Admin Area". I tried using the str replace function but it still won't replace the "Login Area" text. It will instead display the "Admin Area" text right after the "Login Area" text. How do I correct this? Here is my login code:
login.php

<div id="leftcontainer">
	<?php $username="admin"; $password="admin"; ?>
	<div id="loginheader">	
		Login Area
	</div>
	<div id="login"><br>
		<form action="" method="post">
			<font size="2px">Username</font><br>
			<input name="user" type="text" size="16" value="" /><br>
			<font size="2px">Password</font><br>
			<input name="pass" type="password" size="16" value="" />
			<p><input name="sub" type="submit" value="Login" /></p>
		</form>
		<?php		
		if (isset($_POST["sub"])) {
			if (isset($_POST["user"]) and isset($_POST["pass"])) {
				if ($_POST["user"]!=$username and $_POST["pass"]!=$password) {
					echo "<font style='color: blue; text-align: center; font-size:12px; font-weight: bold;'>*INVALID! Try again.</font>";
				} 
			}
		}
		?>
	</div><br><br>
	<div id="guestheader">
		Guest&nbsp;&nbsp;Area
	</div>
		<b><p>* guest 1<br>
		* guest 2<br>
		* guest 3<br>
		* guest 4</p></b>
	
</div>

For log in text just do a simple if statement

<?php
if(($username == $adminusername) && ($password == $adminpassword)) {
echo 'Admin area';
} else {
echo 'Login area';
}
?>

Same goes for the page information stuff

<?php
$page = $_GET['page'];
if($page == 'home) {
display home stuff here
}
elseif($page == 'about') {
display about page here
}
elseif($page == 'contact') {
display content page here
}
else {
display error page or home page
}
?>

My syntax may be wrong on the else and elseif, so you will have to check it. Also, don't forget to santize the variables

Member Avatar for diafol

Looks to me that you're building a pseudo-template with includes. Pretty standard.

In order to get this to work easily (maybe not the best method), have different include files for each page content, e.g.

index.php
about.php
contact.php

includes/
  maintemplate.php

content/
  index.php
  about.php
  contact.php

If all navbar, header and sidebars are common, just place them into the maintemplate.php, so:

index.php

//meta data
$title="whatever";
$description="whatever";
$keywords="whatever";
include("includes/maintemplate.php");

That's it for the index page (and the about and contact pages for that matter).

maintemplate.php

...DTD (html5/xhtml etc)...
<html>
<head>
<title><?php echo $title;?></title>
...etc...
</head>
<body>
<div id="header">
...whatever, nav etc...
</div>
<div id="content">
  <?php include("content/" . basename($_SERVER['PHP_SELF']));?>
</div>
<div id="footer">
...whatever...
</div>
</body>
</html>

Then your content files just hold whatever you need for the content div.

It's cheap and cheerful. OK, you create two files for a single page, but the maintemplate.php file pretty much takes care of everything. This is also just one approach of many. Some like template engines like Smarty and RainTPL. This adds more complexity, so if you're developing a small site, keep it simple.

For general knowledge, if it helps you :

You can also make a div invisible using CSS and make divs dissapear with a javascript functino whenever you feel like it :)

For log in text just do a simple if statement

<?php
if(($username == $adminusername) && ($password == $adminpassword)) {
echo 'Admin area';
} else {
echo 'Login area';
}
?>

Same goes for the page information stuff

<?php
$page = $_GET['page'];
if($page == 'home) {
display home stuff here
}
elseif($page == 'about') {
display about page here
}
elseif($page == 'contact') {
display content page here
}
else {
display error page or home page
}
?>

My syntax may be wrong on the else and elseif, so you will have to check it. Also, don't forget to santize the variables

Thanks for the code that you suggested. Of course I had to edit your code a little so that it would completely work. I have another question. I hope you can help me again. :)

For example for the login form, I was able to change the text from "Login Area" to "Admin Area" when I login. What I want to happen now is when I click on the Home, Contact, and About tabs, I want the text "Admin Area" to remain and not switch back to "Login Area".

The code I used to successfully switch the text are the ff:

<?php
		if ( ((isset($_POST["user"])==$username)&&(($_POST["user"])==$username) &&
			(isset($_POST["pass"])==$password)&&(($_POST["pass"])==$password)) ) {
			echo 'Admin Area';
		} else {
			echo 'Login Area';
		}
		?>

This works fine.

Now for what I want to happen, I tried adding the isset($_GET and isset($_GET):

<?php
		if ( ((isset($_POST["user"])==$username)&&(($_POST["user"])==$username) &&
			(isset($_POST["pass"])==$password)&&(($_POST["pass"])==$password)) ||
			(isset($_GET['home']) || isset($_GET['about'])) ) {
			echo 'Admin Area';
		} else {
			echo 'Login Area';
		}
		?>

But what happened instead is when I click on the Home or About tab, the text "Login Area" in the login form automatically changes to "Admin Area" even though I haven't logged in yet which is not what I want to happen. How do I fix/resolve this?

Here's my complete code for login.php wihout adding yet the one I mentioned above:

<div id="leftcontainer">
	<?php $username="admin"; $password="admin"; $logout="logout"; ?>
	<br><div id="loginheader">				   
		<?php
		if ( ((isset($_POST["user"])==$username)&&(($_POST["user"])==$username) &&
			(isset($_POST["pass"])==$password)&&(($_POST["pass"])==$password)) ) {
			echo 'Admin Area';
		} else {
			echo 'Login Area';
		}
		?>
	</div>
	<div id="login"><br>		
		<form action="" method="post">				
			<?php
			if ( ((isset($_POST["user"])==$username)&&(($_POST["user"])==$username) &&
				(isset($_POST["pass"])==$password)&&(($_POST["pass"])==$password)) ) {
				echo '<p><b><font style="font-size:15px;">&nbsp;&nbsp;+ Item 1</font></b></p>';
				echo '<p><b><font style="font-size:15px;">&nbsp;&nbsp;+ Item 2</font></b></p>';
				echo '<p><b><font style="font-size:15px;">&nbsp;&nbsp;+ Item 3</font></b></p>';
			} else {
				echo '<font size="2px">Username</font><br>';
				echo '<input name="user" type="text" size="16" value="" /><br>';
				echo '<font size="2px">Password</font><br>';
				echo '<input name="pass" type="password" size="16" value="" />';
				echo '<p><input name="sub" type="submit" value="Login" /></p>';
			}
			?>								
		</form>
		<?php		
		if (isset($_POST["sub"])) {
			if (isset($_POST["user"]) and isset($_POST["pass"])) {
				if ($_POST["user"]!=$username and $_POST["pass"]!=$password) {
					echo "<font style='color: blue; text-align:center; font-size:12px; font-weight: bold;'>*INVALID! Try again.</font>";
				} 
			}
		}
		?>		
	</div><br><br>
	<div id="guestheader">
		
		<?php
		if ( ((isset($_POST["user"])==$username)&&(($_POST["user"])==$username) &&
			(isset($_POST["pass"])==$password)&&(($_POST["pass"])==$password)) ) {
			echo 'Admin Options';
		} else {
			echo 'Guest Area';
		}
		?>
	</div>
	<?php
	if ( ((isset($_POST["user"])==$username)&&(($_POST["user"])==$username) &&
		(isset($_POST["pass"])==$password)&&(($_POST["pass"])==$password)) ) {
		echo '<br><b><p style="font-size:15px;">&nbsp;&nbsp;<a href="?infoview=true">+ View Info</a></p>';
		echo '<b><p style="font-size:15px;">&nbsp;&nbsp;<a href="?infoadd=true">+ Add Info</a></p>';
		echo '<b><p style="font-size:15px;">&nbsp;&nbsp;<a href="?infoupdate=true">+ Update Info</a></p>';		
		echo '<b><p style="font-size:15px;">&nbsp;&nbsp;<a href="index.php?'.$logout.'=true">+ Logout</a></p>';		
	} else {
		echo '<b><br><p style="font-size:15px;">&nbsp;&nbsp;+ Guest 1</p>';
		echo '<p style="font-size:15px;">&nbsp;&nbsp;+ Guest 2</p>';
		echo '<p style="font-size:15px;">&nbsp;&nbsp;+ Guest 3</p>';
		echo '<p style="font-size:15px;">&nbsp;&nbsp;+ Guest 4</p></b>';
	}
	?>
</div>

On the login, there is no need to check what page it is and you are using isset completely wrong. Isset will return true or false depending on if the variable is set or not. And if memory servers, a blank forum sends a blank string which evaluates to true. So no need for the double checks. If my memory is wrong, still no need for the double checks. And why are you finding the value of home and etc? Just find the value of one variable called page. That way you don't run into if three pages are set, they all display.

<?php
if (($_POST['user'] == $username) && ($_POST['pass'] == $password)) {
do stuf here
} else {
do stuff here
}

That will be sufficient as for checking if the user is logged in or not. As far as which page it is, at the top set it.

<?php 
$username="admin"; 
$password="admin"; 
$logout="logout";
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 'index';
}

?>
Html here...
<?php
if ($page == 'index') {
display index
}
if ($page == 'about') {
display about
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.