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>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.