Note that there are some explanatory texts on larger screens.

plurals
  1. POGlobal Variables Across Files and Folders in PHP
    text
    copied!<p>I'm building a PHP CMS, but having trouble with variables. I want to be able to have all the variables in an external file, vars.php, and just include that file in every file that requires the variables. The variables all have to do with URLs and folder paths. </p> <p>The problem I'm running in to is that if I set the variables to full URLs (ex: <code>$uploadDir = "http://www.example.com/uploads/";</code>), the scripts don't do what they should. Same thing if I use absolute paths (ex: <code>$uploadDir = "/uploads/";</code> or <code>$uploadDir = "/full/server/path/uploads/";</code>).</p> <p>If I use full URLs, it seems like it at least tries to work, but doesn't. If I use the full server path or absolute path, I get some error about that path not being allowed. The files are all stored in <code>/edit/</code> or <code>/edit/(sub-folder-name)/</code>, if that helps.</p> <p>I'll look around for some code examples where I would be using this, and update this post ASAP.</p> <p>Thanks.</p> <p>UPDATE:</p> <p>Some of the variables from this code snippet aren't included, just didn't think I should post a huge PHP script.</p> <p>Example of <code>$pageDir</code>:</p> <pre><code>// The below 2 lines are actually in vars.php, which is included in this file. $pageDir = "http://www.example.com/edit/pages/"; $url = "http://www.example.com/"; if ($_POST["page"] &amp;&amp; $execute == TRUE) { $live = $_GET["p"] . ".php"; // The below line is how this used to be set up. // $handle = fopen("pages/$page", "w"); // The below line is how the new version should be set up. $handle = fopen("$pageDir/$page", "w"); fwrite($handle, $_POST["page"]); fclose($handle); // The below line is how this used to be set up. // echo("&lt;p&gt;Page successfully saved. &lt;a href=\"../$live\" target=\"_blank\"&gt;Click here to view this page.&lt;/a&gt;&lt;/p&gt;\n"); // The below line is how the new version should be set up. echo("&lt;p&gt;Page successfully saved. &lt;a href=\"$url/$live\" target=\"_blank\"&gt;Click here to view this page.&lt;/a&gt;&lt;/p&gt;\n"); $execute = FALSE; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload