Hey guys,
Is there anyway to use the include or require functions similar to how you would use an href link with a relative link starting with the root?
So I’m trying to do this include(“/check.php”); instead of crap like this include(“…/…/…/check.php”);
Include knows nothing about your website path, but you can do something similar by using DOCUMENT_ROOT
include($_SERVER['DOCUMENT_ROOT'] . '/check.php');
Quite interesting. Thanks!
Can you provide a little bit of explanation as to why PHP doesn’t know about the document root but HTML does?
PHP is prepared on the server side, and then send to whatever made the request. HTML knows even less (that is, nothing) about the server’s document root. That’s why you need to interrogate the server to retrieve that information.
so am I not safe using root linking with HTML? Because I do it quite often
When using PHP to create the HTML code, that’s fine.
well I have html code in a php file, for example
<script type="text/javascript" src="/jquery.js"></script>
Is that okay?
It will always assume that this means www.whatever.com/jquery.js
right?
svcghost:
well I have html code in a php file, for example
<script type="text/javascript" src="/jquery.js"></script>
Is that okay?
It will always assume that this means www.whatever.com/jquery.js
right?
Nearly always. When the base tag is used, that changes the base to something else, but other than when that is used, you’re okay.