how do i display a file on a page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

how do i display a file on a page

Post by chris_s_22 »

this is my page im using as you can see i use include so i only after edit one page if i need to make changes in the future.

Code: Select all

<?php 
include_once 'Connect.php';
?>
<html><head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
 
<body>
<div class=logo><?php include "logo.php";?></div>
 
<div class=navigationbarbox><?php include "navigationbar.php";?></div>
 
<div class=welcome>License detilas here</div>
 
<div class=footerbox><?php include "footer.php";?></div>
</body>
</html>
however i want this page to dispaly another navigationbar if not logged in. i thought i just have to do a call to my is_authed function and then display the correct one
<?php
if (!is_authed())
{
echo "<div class=navigationbarbox><?php include "navigationbar.php";?></div>";
}
else
{
echo "<div class=navigationbarbox><?php include "navigationbar2.php";?></div>";
}
?>
i think the problem is my echo statements can anyone tell me what i should be doing
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: how do i display a file on a page

Post by iankent »

chris_s_22 wrote:

Code: Select all

 
<?php
if (!is_authed()) 
{
     echo "<div class=navigationbarbox><?php include "navigationbar.php";?></div>";
}
else
{
    echo "<div class=navigationbarbox><?php include "navigationbar2.php";?></div>";
}
?>
 
i think the problem is my echo statements can anyone tell me what i should be doing
You're right, it is your echo statements. You can't use <? and ?> within echo statements because echo statements are, by their nature, already within PHP. You'd need to do this instead:

Code: Select all

 
<?php
if (!is_authed()) 
{
     echo "<div class=navigationbarbox>";
     include "navigationbar.php";
     echo "</div>";
}
else
{
     echo "<div class=navigationbarbox>";
     include "navigationbar2.php";
     echo "</div>";
}
?>
 
edit: what do you use to edit your PHP files? if you just use notepad or similar, consider getting a code editor that gives syntax highlighting, and if you use something like NuSphere it even gives you design-time debugging. Makes it much easier to spot errors, as in this case the include() keywords weren't highlighted when they should be, an indicator that they aren't going to work!
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: how do i display a file on a page

Post by chris_s_22 »

yeah i normally use dreamweaver though not at home so using notepad

but thanks working has it should now
Post Reply