limitphp Posted December 16, 2008 Share Posted December 16, 2008 I have a page that is in a directory, mysite.com/artist/the-strokes/ but the style sheet is in the mysite.com/ directory. how do I write: <LINK REL=StyleSheet HREF="style.css" TYPE="text/css"> so it can grab the style.css file in the mysite.com/ directory (root directory)? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/ Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 nevermind...I got it. <LINK REL=StyleSheet HREF="../../style.css" TYPE="text/css"> Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-716915 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 Wow, even though, /artist/ and /the-strokes/ are fake directories, I'm going to have to add ../../ to all the src for images and style sheets and javascripts. Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-716916 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 crap...now the links don't work either. They all say: http://localhost/greckle/artist/The-Strokes/index.php instead of http://localhost/greckle/index.php is there something else I can do to fix all of this? so i don't have to keep adding ../../ to all the hrefs as well? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-716918 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 Is there like a header or something that can tell all the SRC to go up two directories? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-716927 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 there must be something that is done to fix all the links when you do a url rewrite? and you add extra false directories. Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717013 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 I always set constants for siteurl and document url using: $_SERVER['DOCUMENT_ROOT'] and $_SERVER['HTTP_HOST']; IE: <?php $folder = ""; // set this to be "/folder" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/"); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); Then in your script just use this: <LINK REL=StyleSheet HREF="<?php echo SITEURL; ?>style.css" TYPE="text/css"> That way it keeps the site dynamic and you can put it on any server in any directory and it works Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717032 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 I always set constants for siteurl and document url using: $_SERVER['DOCUMENT_ROOT'] and $_SERVER['HTTP_HOST']; IE: <?php $folder = ""; // set this to be "/folder" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/"); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); Then in your script just use this: <LINK REL=StyleSheet HREF="<?php echo SITEURL; ?>style.css" TYPE="text/css"> That way it keeps the site dynamic and you can put it on any server in any directory and it works Thanks, what do you use DOC_ROOT for? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717038 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 actually, I just used your script.... define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); and instead of going to: http://localhost/greckle/register.php it went to: http://localhost/register.php it skipped the greckle I'm using wamp server Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717044 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 <?php $folder = "greckle/"; // set this to be "folder/" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/" . $folder); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); The DOC_ROOT is for including php files with include See above, the $folder is the folder containing the script. That should fix you up. Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717047 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 <?php $folder = "greckle/"; // set this to be "folder/" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/" . $folder); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); The DOC_ROOT is for including php files with include See above, the $folder is the folder containing the script. That should fix you up. Oh I see. So, since I'm running it locally, and my site is in a folder named greckle....I have to put greckle for the folder name..... But when it goes live, and its just in the public_html folder, I won't need the $folder = greckle; part? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717051 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 <?php $folder = "greckle/"; // set this to be "folder/" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/" . $folder); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); The DOC_ROOT is for including php files with include See above, the $folder is the folder containing the script. That should fix you up. Oh I see. So, since I'm running it locally, and my site is in a folder named greckle....I have to put greckle for the folder name..... But when it goes live, and its just in the public_html folder, I won't need the $folder = greckle; part? thanks! Yep pretty fancy huh? =) Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717058 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 there's no way to automatically make all the SRCs have the $_SERVER['HTTP_HOST'] . "/" . $folder without typing it (<?php echo SITEURL; ?>) in each href, javascript, stylesheet, img src? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717060 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 Look at the HTML tag "base" <base href="http://www.site.com/foldera" /> Should do it for you. Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717066 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 Look at the HTML tag "base" <base href="http://www.site.com/foldera" /> Should do it for you. sweet..... is there one for img src or the other stuff? link stylesheets? I'm confused on how to use the DOC_ROOT with the include. $folder = "greckle/"; // set this to be "/folder" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/"); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); include("connGreckle.php"); my include file is in the same directory as the other pages. So, wouldn't I use SITEURL for it? or it has to be the actual location...like c:/wamp/www? if so, would I need to add the $folder to the DOC_ROOT like you did with the SITEURL? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717079 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 <?php $folder = "greckle/"; // set this to be "/folder" if the script is included in a folder define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/"); define("SITEURL", "http://" . $_SERVER['HTTP_HOST'] . "/" . $folder); include(DOC_ROOT . "connGreckle.php"); For the base that will change every tag on the page with a src or href of "folder/file.php" or "file.php" to have the SITEURL infront of it. <base href="<?php echo SITEURL;?>" /> <img src="logo.jpg"> <!-- this is now "http://www.mysite.com/folder/logo.jpg" Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717085 Share on other sites More sharing options...
limitphp Posted December 16, 2008 Author Share Posted December 16, 2008 yes....the base tag worked beautifully! thanks. would my include be include(DOC_ROOT."connGreckle.php"); ???? why don't you use the base tag instead of writing <?php echo siteurl;?> in every href? Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717094 Share on other sites More sharing options...
premiso Posted December 16, 2008 Share Posted December 16, 2008 yes....the base tag worked beautifully! thanks. would my include be include(DOC_ROOT."connGreckle.php"); ???? Should be. Quote Link to comment https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/#findComment-717096 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.