Jump to content

Include Files and Variable Scope


scurker

Recommended Posts

I'm having issues when including a file across an SSL connection, and the variable scope inside the include file. When including an include file from my HTTP domain, it seems to have problems using functions defined inside the include files on the HTTP domain, as well as unable to use variables defined from withing the HTTPS domain.

 

Here's the setup I currently have:

 

I have a template file that is included on every page so that I can easily change out or update any of the includes. Example:

<?php

  $root = '/path/to/root/dir';

  $menu = $root.'/includes/menu.inc.php';
  $header = $root.'/includes/header.inc.php';
  $footer = $root.'/includes/footer.inc.php';

?>

 

Inside the include files, I may also include the root variable (to allow me to change easily from a local test server, to a web server) as such:

header.inc.php

<head>
  <style type="text/css" media="all">@import "<?php echo($root) ?>/css/stylesheet.css";</style>
</head>
<body>
  <img src="<?php echo($root) ?>/images/logo.png" />
...

 

This works great when I have everything on the same HTTP server, with no problems at all. Now the issue comes along where I also have a few pages which require SSL, which I have on their own HTTPS address. PHP is able to successfully include the files, AND output all the contents. However, in the case above (header.inc.php) any variables defined outside the include files can not be found, giving $root a value of nothing. In addition, any functions defined inside the include files can not be found as well which makes my database connectivity unavailable.

 

I've attempted to change $root to define('ROOT', '/my/root/path') as well, and the same issue occurs.

 

My goal is ultimately to only have the pages when needed available via a HTTPS request, but any shared files available only on one server, so I don't have to update multiple files anytime a change is made. Am I missing something, or is what I'm attempting to accomplish just not possible?

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.