Forum Moderators: coopster

Message Too Old, No Replies

php in css & variable scope

can the php code of an external CSS file access variable from mother script

         

alexis

3:49 pm on Dec 24, 2004 (gmt 0)

10+ Year Member



I was happy to see php can be executed in an external css file (http://www.webmasterworld.com/forum88/5648.htm)

I do want to keep them external as I want to hide them from old Browsers with @import.

How can I get the php code inside the CSS to see variables from the page it's loaded in? or form GET or POST? I know it can access server variables and I know I cannot set server variables from php.

Any idea for a workaround that?

jollymcfats

5:50 pm on Dec 24, 2004 (gmt 0)

10+ Year Member



How can I get the php code inside the CSS to see variables from the page it's loaded in?

You can't. In HTTP there's no data relationship between a page and the media it references. A page loading css is no different than the user following a link to a different page- its a separate, fresh HTTP request that knows nothing about other requests. But!

or form GET or POST?

Since your dynamic CSS gets its own HTTP request, you can send it parameters by GET. (POST too, but not usefully.) Rendered to HTML, it would look like this:

@import url("style.css?borders=fat&colors=dark");

You could build such a link in your loading page with echo and variable substitution, sending along the variables you're interested in.

Sessions are also a way to share data across requests, and would work for this purpose if your dynamic css page is setup to not cache in the browser.

dreamcatcher

2:30 am on Dec 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And welcome to WebmasterWorld alexis. :)