Page 1 of 1

included page variables?

Posted: Wed Jun 19, 2002 2:30 pm
by Patriot
This is kind of hard to explain.
Here:

Index.php includes Title.php and Main.php
Title.php has all the Title information (<title>/ <head>)
Main.php has the variable i need

Is it possible to have Title.php display the Main.php variables.



If you still dont get it:
INDEX.PHP
has:
include main.php
include title.php

MAIN.PHP
has:
$Page_Name = Main Page

TITLE.PHP
has:
<title>
<?
print "$Page_Name"
?>


can this work?
if you still dont understand this...i have no further advice for you, rather than getting help :wink:

Posted: Wed Jun 19, 2002 2:39 pm
by volka
this may work, if the code in title.php is invoked after the variable is set in main.php. i.e

Code: Select all

//TITLE.php
<?php function writeTitle() &#123;
?><title><?= $Page_Name ?></title><?php 
&#125; ?>

//MAIN.php
require('TITLE.php');
$Page_Name="My Page";
writeTitle();

Posted: Wed Jun 19, 2002 2:48 pm
by e+
Yes you can. Try it and see.

Posted: Wed Jun 19, 2002 2:55 pm
by Patriot
Fatal error: Cannot redeclare writetitle() (previously declared in S:\Inetpub\sites\smyr\targetroot\title.php:4) in S:\Inetpub\sites\smyr\targetroot\title.php on line 3

Posted: Wed Jun 19, 2002 3:04 pm
by e+
Sorry My brain hurts. :oops:
Why don't you include main.php into title.php and then include title.php in index.php, I know that works fine as I use it myself.

Posted: Wed Jun 19, 2002 3:11 pm
by Patriot
no, i'm using table cells to split it in pieces, and, title.php is used in atleast 14 other pages.

Posted: Wed Jun 19, 2002 3:22 pm
by twigletmac
To solve problems with redeclaring functions try using include_once().

Mac