Jump to content

Two files, one variable


elefant

Recommended Posts

Hi.

 

Let's say, hypothetically... You make a header script. In this header you make the page title for the hypertext a variable.

<title><?=$page_title?></title>
I've also tried, echo with " and ' and also ended the declaration properly with ; in many of the ways I've attempted to get this to work

 

Now, in a seperate file, let's say it is just some random page on your website, you...

<? $page_title = "This is my page"; 
include_once('header.php'); ?>

 

This application works wonderfully... If, that is, the header and random webpage are located in the same directory... But, at least to me, this nearly defeats the whole purpose. Sure, it is easier to edit one header, possibly linking to 50 files per directory, but isn't it easier to edit one header in total?

 

My question is, and I know this can be done as massive software like phpBB/SMF use only one header, how in the world can I get a variable to pass from one file to another when one of the files is in a completely different directory stack?? (And yes, I am aware that you can ('http://website/dir1/dir2/file.php') call a file in that manner but even this fails to translate variables located in a different stack, at least how I'm doing them now).

Link to comment
Share on other sites

ok i think i know what you want. In your include part you just set up the directory.

 

../ = route

 

So if you make a file call php, which stores all you php file you will include in like

 

include_once('../phpfolder/header.php')

 

I think that is correct if not remove the ../ and just and phpfolder

Link to comment
Share on other sites

Thanks but that does not help.

 

I've tried that.

The situation is this -

Scenario a)

root/dir1/dir2/file where variable is defined

In the same dir the file using the variable is used

When this is the arrangement the variable is passed.

 

Scenario b)

root/dir1/dir2/file where the variable is defined

root/dir3/dir4/file where the variable is used

With this arrangement the variable fails to translate.

 

It does not matter what I do when calling header, if it's not in the same directory stack it simply doesn't translate. It could be any of the following

./dir3/dir4/file = fail

../../file = fail

http://propersubdomain.site.com/scripts/file = the page loads but no variable translation in sight

http://site.com/subdomainasfolder/scripts/file = see above

 

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.