TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-12-2008, 01:53 AM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default Whats with the weird external stylesheet links?

Okay... Please share the secret. Why and how do they do this:
<link rel="stylesheet" type="text/css" media="all" href="http://<snip>.com/?css=styles/index.v.1195440872" />

and also, whats with the W3C.... How did they make a stylesheet do this:

http://www.w3.org/StyleSheets/TR/W3C-WD

They just link to the directory and it goes to the stylesheet. I feel violated. This goes against everything I was taught in elementary school!
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-12-2008, 03:44 AM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

As to your first question, are you asking about the link tag or the way the script linked returns the CSS? It appears to be a relatively generic script receiving a GET string, processing it and returning a stream of CSS to be included in the document.

The W3C, I'm not positive, but I think the 'W3C-WD' is the stylesheet. It just doesn't have the .css extension.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 04-12-2008, 03:50 AM   #3 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

The way the script returned the CSS, and why it was used that way.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-12-2008, 08:36 AM   #4 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 24
Thanks: 13
sidisinsane is on a distinguished road
Default

Quote:
Originally Posted by Aaron View Post
... How did they make a stylesheet do this:

http://www.w3.org/StyleSheets/TR/W3C-WD ...
I'm sure there are several ways of doing this. One would be to place an index.php in the W3C-WD directory, which is parsed as css by sending a CSS header. Like this:
Code:
<?php
// Send CSS header
header("content-type: text/css");
header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");

// Your styles
...
?>
sidisinsane is offline  
Reply With Quote
The Following User Says Thank You to sidisinsane For This Useful Post:
TlcAndres (04-12-2008)
Old 04-12-2008, 09:51 AM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

For the CSS file with a versioning string, it's simply to make sure that when a new version of the CSS file is uploaded people can immediately see the changes (because the URL will change) since the cache won't be made for that particular URL. A simple solution would be to load in the specified CSS file (using Apache, PHP, etc.) or a default one if it does not exist (or 404 ;)).

With the stylesheet on the W3C site, the correct file will show up because their web server is using Content Negotiation (Apache). Full details are at the 'Apache' link just posted, but essentially (depending how you have things set up) Apache will look for files in that location and deliver the best match, if any. For example, on my local server I can access http://localhost/mydir/myfile which might call a PHP script if there is a myfile.php available. If I created a myfile.html and accessed the same URL, the displayed page would be the HTML document because that overrules the PHP file. If I got rid of the HTML and PHP file but instead placed a myfile.png there, the same URL would display the image. (Note: This is not mod_rewrite!)

If you try to access http://www.w3.org/StyleSheets/TR/W3C-WD.css then you'll get the stylesheet. If you try instead to access http://www.w3.org/StyleSheets/TR/W3C-WD.html, you'll get a 300 Multiple Choices header with in this case a list of available files.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
SOCK (04-12-2008)
Old 04-12-2008, 09:58 PM   #6 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Garrett is on a distinguished road
Default

I used a similar method, to allow quick access to editing the CSS from the database. I just used a text/css header in PHP and outputted the CSS.

Same thing goes with RoR, look at:
Code:
<link href="http://asset2.projectpath.com/stylesheets/cache/all.css?1207968108" media="screen" rel="stylesheet" type="text/css" />
<link href="http://asset3.projectpath.com/stylesheets/print/application.css?1207968082" media="print" rel="stylesheet" type="text/css" />
Garrett is offline  
Reply With Quote
Old 04-13-2008, 08:22 PM   #7 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Wouldn't you have to link to a .php file? I mean, linking to .css would lead you to a file not there, but linking to a .php file would give you a css file, wouldn't it?
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-23-2008, 11:15 AM   #8 (permalink)
The Contributor
Good Samaritan 
 
d4v1d's Avatar
 
Join Date: Dec 2007
Location: Durban, South Africa
Posts: 51
Thanks: 1
d4v1d is on a distinguished road
Default

mod Rewrite :)
d4v1d is offline  
Reply With Quote
Old 04-27-2008, 08:13 PM   #9 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

mod rewrite is overrated and queer.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-27-2008, 08:24 PM   #10 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

I do admit that mod_rewrite's syntax is a bit odd but it's dead useful.
__________________
"What everyone seems to forget is that while knowledge certainly is something - it's the implementation of knowledge that brings power" - Andres Galindo.
TlcAndres is offline  
Reply With Quote
Old 04-27-2008, 09:59 PM   #11 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

useful for what?
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-27-2008, 10:23 PM   #12 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

A LOT.

Code:
RewriteRule ^users/info/([A-Za-z0-9_]+)/?$ users/info.php/$1
RewriteRule ^users/([A-Za-z0-9]+)/?$ users/$1.php
That's a small snippet of some rules I'm using right now in developing my site. This is doing a few things; first and foremost, all my urls are readable and SEO friendly. Secondly, it's adding another minor level of security to my scripts. None of my scripts use GET, so GET can't be abused. On top of that, thanks to the regular expressions, if the URL doesn't conform to the guidelines above, the user just gets a 404 returned, so it's harder to inject malicious data. All input, whether from this method or POST is sanitized and validated internally as well, but all the little extras I've implemented add up to what I believe to be a pretty bulletproof operation.

mod_rewrite is damned cool, IMHO.
-m

Last edited by delayedinsanity : 04-28-2008 at 04:30 PM.
delayedinsanity is offline  
Reply With Quote
Old 04-28-2008, 03:40 PM   #13 (permalink)
The Wanderer
 
blayne4k's Avatar
 
Join Date: Apr 2008
Location: Trapped in my own little world.
Posts: 14
Thanks: 0
blayne4k is on a distinguished road
Default

yea mod_rewrite can be used for alot, a few of my favorites is getting myspace to post some dynamic images on my site, since they block .php extensions in files

its good for SEO, since google and other sites thing page.php?id=1 and page.php?id=2 is the same page if you wanted forums and such to get crawled youd need a modrewrite to make page-1.php and page-2.php although id make that prettier. This site even uses it for SEO
blayne4k is offline  
Reply With Quote
Old 04-28-2008, 08:44 PM   #14 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

You're wrong. Google understands dynamic links. There's no need to respond to this thread anymore unless you have something important to say about dynamic stylesheet links. This isn't about mod_rewrite.

However, thanks for all of your help :P
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-28-2008, 08:57 PM   #15 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Whoah, somebody had a bad date with mod_rewrite. Why all the hostility?

Google understands them, google just doesn't care for them. So if you want to rank higher, you won't use dynamic links. Plus, if you want your site to be more user-friendly, you won't use them. Plus, if you want your site to be a little more secure from front-door attacks, you won't use them. Plus, I could go on forever.

Have you ever once had a conversation in person that didn't start on one topic and end on another? Relax.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-28-2008, 09:06 PM   #16 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

All the hostility is as soon as I put in
Code:
RewriteEngine on
I get a 500 internal server error.

edit: just turned on the rewrite module. Now my problem is the weird regex that I have to learn.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-28-2008, 09:12 PM   #17 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Are you running a test machine that does that, or is it on a remote host? Because it sounds to me like the module just isn't loaded in - for some stupid reason mod_rewrite is shipped with apache but not turned on (well, I think it's stupid). If you're on your own box, you can open up httpd.conf and edit this line:


#LoadModule rewrite_module modules/mod_rewrite.so

.. remove the # and you get ..

LoadModule rewrite_module modules/mod_rewrite.so


And then as long as allowoverrides is on, you can mod_rewrite to your hearts content. If your host doesn't have it on however, like I just discovered (#@$@#$@) then you may be outta luck. Which is why I wish Apache had it turned on by default, because then my host probably would too, and I could happily use it while they sat in their nice little air conditioned offices thinking they was the shiznit.
-m
delayedinsanity is offline  
Reply With Quote
Old 05-08-2008, 07:57 AM   #18 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

After loading the module, reboot your apache server.
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 05-08-2008, 08:44 AM   #19 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Aaron View Post
All the hostility is as soon as I put in
Code:
RewriteEngine on
I get a 500 internal server error.

edit: just turned on the rewrite module. Now my problem is the weird regex that I have to learn.
It's not that hard, I learned it in like 5 minutes.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:23 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design