Jump to content

[SOLVED] escaping out of a directory


limitphp

Recommended Posts

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)?

Link to comment
https://forums.phpfreaks.com/topic/137231-solved-escaping-out-of-a-directory/
Share on other sites

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?

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

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?

 

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

<?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.

<?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!

<?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? =)

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?

<?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"

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.