Jump to content

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"

 

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.