homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Detect relative paths in a linked CSS stylesheet?
JAB Creations

 1:08 am on Mar 27, 2008 (gmt 0)

I'm considering the option of allow people to add a URL to an external style sheet so they can adjust how my site appears when they visit. However if I did so I want to prevent those stylesheets from using relative paths to files such as background-images and cursors as some browsers do not correctly interpret relative paths. I would also require the absolute paths not to encase URLs in single or double quotes for backwards compatibility (my site tentatively supports IE on OSX for example). I essentially want to prevent 404s coming from other people by enforcing the rule via PHP.

So is it possible to access an external CSS file and determine if there are any relative paths based on the required rule that if a line contains the string "url" it must match "url(http://"?

- John



 1:55 pm on Mar 28, 2008 (gmt 0)

hmmm, you would have to open the remote file and then use regex to find every path in the file and then test them to make sure their pattern matches the pattern of an absolute url.

It seems like a lot of work, then what happens if they change the file?


 3:17 pm on Mar 28, 2008 (gmt 0)

Since the stylesheet is only applied to the user who has chosen to use it, why do you bother correcting _their_ errors?

JAB Creations

 5:36 pm on Mar 28, 2008 (gmt 0)

Their errors translate in to more work for me if I have to wade through a pool of their 404s because they used relative paths considering it's cross-domain CSS.

Would this be a complicated regex? Would it be difficult to setup some sort of Apache anti-404 script that disallows images to load from my site if the referrer is a cross-domain CSS file? If that were possible I could skip the PHP script altogether possibly. I think off-hand at least.

- John

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved