Jump to content

Using DEFINED variables in a webpage


otuatail

Recommended Posts

Cant work oout how to put the code snipets in the quick reply !

 

*** defaults.inc ***

Define (BANNER,  "images/top.jpg");

 

*** index.php ***

include ("defaults.inc");

// --------

$banner = BANNER;

// --------

<div id="PageTitle">

<img src="<?=$banner?>" alt="Banner">  //defaults.inc

</div>

 

Now just try this on one page:

<?php 

define(BANNER,  "images/top.jpg");

?>
<div id="PageTitle">
   <img src="<?php echo BANNER ?>" alt="Banner">
</div>

 

Then if that works do:

defaults.inc

<?php 

define(BANNER,  "images/top.jpg");

?>

 

and your index page:

<?php 

include "defaults.inc";

?>
<div id="PageTitle">
   <img src="<?php echo BANNER ?>" alt="Banner">
</div>

 

and you shouldn't have to do this:

$banner = BANNER;

it kind of defeats the purpose of your defaults file

well, looking at the source code of your page:

 

Define (BANNER,  "images/top.jpg");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Home Page</title>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="stylesheets/CMS.css" type="text/css">
</head>

<body>

<div id="PageTitle">
<img src="BANNER" alt="Banner">  //defaults.inc
</div>

<div id="menu">
<ul id="tabnav">

<li>Home</li>
   <li><a href="page2.php">Page 2</a></li>

</ul>
</div>


<div ID="w3c">
<IMG src="images/w3c.gif" alt=""><br><IMG src="images/css.gif" alt="">
</div>


<div id="PageContent">
<p>This is sample page 3</p>
</div>
</body>
</html>

 

are you using

 

<?php Define (BANNER,  "images/top.jpg"); ?> // or just missing out the <?php and ?>

Yes this getting somwhere it dosn't matter if i have <?php or just >?

and now works without the echo as in <?=BANNER ?>

 

the problem seems to be this.

 

// include ("defaults.inc");

define(BANNER,  "images/top.jpg");

 

it likes it idf the definition is on the page but not drawn from a seperate file. The reason for the seperate file is I will have a lot of pages and keeping the image name in one place would be better.

 

I kbow I need include ("defaults.inc"); at the top of the page.

Problem is it won't work with includes

If I put define(BANNER,  "images/top.jpg"); directly on the same page it works.

 

include ("defaults.inc");

// define(BANNER,  "images/top.jpg");  This will not work

 

 

// include ("defaults.inc");

define(BANNER,  "images/top.jpg");    This will  work

 

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.