included page variables?

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
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

included page variables?

Post 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:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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();
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

Yes you can. Try it and see.
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

Post 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
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post 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.
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

Post by Patriot »

no, i'm using table cells to split it in pieces, and, title.php is used in atleast 14 other pages.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To solve problems with redeclaring functions try using include_once().

Mac
Post Reply