PDA

View Full Version : Control CSS server side



meow
May 14th, 2001, 19:00
Do you know where I can get server side scripts that let the user change Style Sheet or disable CSS by clicking a link? Not ASP. I've been searching for hours. :(

lucifer
May 15th, 2001, 09:39
easy way is to use php

in your page have link to css '<?=$style?>.css'

so if you have a link page.php3?style=1 it'll use 1.css etc

you'd have to add ?style=<?=$style ?> to all the links though and have some basic error checking for valid $style

with the code you've being posting recently you should have no difficulties ;)

meow
May 15th, 2001, 17:43
Lucifer, you are my favorite! ;) *meow purring friendly*
I knew there would be an easy way. Only I don't get sh*t. I've never even installed a php script. Would you please help me some more? *still purring*

With link do you refer to link rel or the a href they should click on? Could you post a complete sample of how it would look like? *meow purring like a helicopter*

Eh...what smart code should I have posted? The only programming I know a little about is in a language that is so limited that no one knows it exists. :)

lucifer
May 15th, 2001, 20:56
Am I a sucker? (http://www.the-antichrist.com/meow/page.php3)

lucifer
May 15th, 2001, 21:09
Originally posted by meow
Eh...what smart code should I have posted?



Originally posted by meow
I tried this on f2s:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !>http://www.blah.f2s.com [NC]
RewriteRule /* http://www.blah.f2s.com/bad.html [R,L]


;)

meow
May 15th, 2001, 21:32
O, Prince of Darkness. I worship thee.
Can I come and live with you? :D

The .htaccess? But I didn't manage to get the crap to work.

Will you teach me how to do it with Perl/SSI now? :p That is possible, right? And to the weekend maybe some basic classes in Perl? He he. ;)

Thank you very much!

Purrrrrrrrrrrrrr! ;)
meow
proud owner of 500MB/10GB Unix space to the total cost of $14 - eat it suckers! :D

lucifer
May 15th, 2001, 22:45
I am a bigger sucker (http://www.the-antichrist.com/meow/meow.pl)


so what's on this 500MB/10GB Unix space?

Q. 500MB/10GB = 0.05MB?

meow
May 15th, 2001, 23:10
WHOOOPIE!!! Wow. Now I'm in love. :o

Thank you so very much. I've asked about this at several places and all I have got is 100 line long ASP scripts. I knew it had to be simpler than that.

Huh, my 500Megs are quite empty. The Directoris one I got because I want a playground and learn some more useful scripting than the unknown language I have been fiddling with. Then Yupapa dropped another one in my knee. Wasn't planned. I had just signed up for one of the free accounts, not applied for anything. Guess he is just a nice fellow.

Boy, are you good or what?!? I'm off buying black candles. :D

lucifer
May 15th, 2001, 23:36
do it the php way

put the code <? ... ?> in a file called css.php3
make sure it has the <? ?> bits

put <? include "css.php3"; ?> in the header of all your pages so that they include it (php is very tricky ;))
use a path if needed

add ?colour=$colour to all your hrefs on the pages and name them *.php3

smile :)

you might need to use <?php instead of <? depending on your setup <?php always works but is harder to spell



Boy, are you good or what?!?

thinks...

meow
May 16th, 2001, 02:45
Put the stuff in an external php file and include it with a snip of inline.php? Yes sir. I'll do tomorrow.

I after much ado got the first php thing to work. I tried at Directoris and f2s. Turned out that f2s decided to cache my pages for the second time ever and that Directoris has php4 . I renamed the file to php and then it worked.

Question: does the extension .php always work? If so way bother with php3, php4 and so on? If I use .php'n' must n match the verion of PHP installed on the server even if the server has an later version than I declare to use?

This was fun. :p

lucifer
May 16th, 2001, 10:21
the extension is just what your server wants to use you can set *.meow files to be run as php

my server doesn't let me use .php but's fine with .php3 even though they upgraded to php4 just .php isn't set up as an extension. It's a pain cos I have done things on my machine .php and .php3 are ok and i'd done the pages as .php so it didn't work on the server till I swapped them.

it's like the <? <?php thing depends on your setup

the extension doesn't effect the version of php used unless you had more than one copy and set diff extensions to call different ones (who would?)

I did a line wrong on that last post :o

add ?colour=$colour to all your hrefs on the pages

?colour=<?=$colour?>

needs the <? ?> to go into php otherwise it's just good old html

<?= same as <? echo but doesn't work in php3 hence my servers upgrading should get them to let .php be an extension too but involes sending email :(

meow
May 16th, 2001, 10:32
Aha, same thing with the extension as with SSI? So theoretically it could be .html? Then severs use the version number just to show off their software...Stupid. Looks ugly.

Thanks for the update. I haven't got around to test that one yet. I think you just saved me some pain (again). :)

lucifer
May 16th, 2001, 10:42
Originally posted by meow
So theoretically it could be .html?

yep but your server would grind trying to process all that html as php (which it is - almost)

I quite like php3 it makes it look complicated also I've always had a soft spot for mp3 php4 is ugly though

meow
May 16th, 2001, 11:18
3 is one of the magic numbers. You'll have to wait for php7 now.

lucifer
May 16th, 2001, 12:23
I'll hold out to php666 :cool:

meow
May 16th, 2001, 13:29
Touché. :D Good one.

angeth
May 16th, 2001, 15:38
Originally posted by lucifer
the extension is just what your server wants to use you can set *.meow files to be run as php


Okay, I'm going to guess that I'm just being dense and not getting how to do this...But could you explain it in a little more detail?

Angela, who would love you forever if you did.

lucifer
May 17th, 2001, 08:44
from my httpd.conf config file for apache web server



# PHP

ScriptAlias /php/ "c:/usr/php/"

AddType application/x-httpd-php .php

AddType application/x-httpd-php .php3

AddType application/x-httpd-php .phtml

Action application/x-httpd-php "/php/php.exe"



this sets .php .php3 .phtml files to be run by php and the output sent to the browser

if I add



AddType application/x-httpd-php .meow


then it runs .meow files as php :D

meow
May 17th, 2001, 09:07
Originally posted by lucifer
then it runs .meow files as php :D

What a perfectly lovely idea! :D

Whould this work in an .htaccess? Heavely guessing here...:o

AddType application/x-httpd-php .php .php3 .phtml .meow
AddHandler server-parsed .php .php3 .phtml .meow

lucifer
May 17th, 2001, 09:22
meow

here is the updated css.php



<?
# ERROR CHECK AND INCLUDE CSS
if ($col=="red" || $col=="green" || $col=="blue"){
echo "<link rel='stylesheet' href='$col.css' type='text/css'>";
}

# GET CURRENT PAGE INFO FOR CHANGER
$pageinf=parse_url($REQUEST_URI);
$pageurl=$pageinf['path'] . "?col";

# SET UP VARS TO INCLUDE ON PAGES
$changelink="<a href='$pageurl=red'>red</a> | <a href='$pageurl=green'>green</a> | <a href='$pageurl=blue'>blue</a>";

$link="?col=$col";
?>

new features

links between your pages become :D

<A href="mypage.php<?=$link?>">...</a> :)

and put <?=$changelink?> on the page where you want the colour changer :cool:

limitations

the colour changer link kills all query info on the url you could change it so it doesn't :(


if you have session tracing stuff on your php setup you could do away with having to rewrite the links by having them re-written on the fly but when you have seach and replace you don't really need it

I think you have a rival - cat fight ?!!?

lucifer
May 17th, 2001, 09:37
Originally posted by meow
Whould this work in an .htaccess? Heavely guessing here...:o

AddType application/x-httpd-php .php .php3 .phtml .meow
AddHandler server-parsed .php .php3 .phtml .meow
[/B]


Not sure not that hot on .htaccess but some info (http://free.prohosting.com/~sampieri/freefaq/g_htaccess.shtml) suggests that it could be done

server-parsed sounds like it'd SSI the page not php it


should the addtype be text/html looks like it's what's sent to the browser

who know give it a whirl :)

gyrbo
May 18th, 2001, 18:48
Originally posted by meow
WHOOOPIE!!! Wow. Now I'm in love. :o

Thank you so very much. I've asked about this at several places and all I have got is 100 line long ASP scripts. I knew it had to be simpler than that.

Huh, my 500Megs are quite empty. The Directoris one I got because I want a playground and learn some more useful scripting than the unknown language I have been fiddling with. Then Yupapa dropped another one in my knee. Wasn't planned. I had just signed up for one of the free accounts, not applied for anything. Guess he is just a nice fellow.

Boy, are you good or what?!? I'm off buying black candles. :D
Doesn't directoris has only 250MB and 5GB?

meow
May 19th, 2001, 03:23
Thanks Lucifer! :)
This is great stuff. I must save this whole thread so I can chew it all.
Do you hear me purring? ;)

Gyrbo -
Yes, you are right. Directoris is 250/5. But Yupapa gave me and some others free pro accounts the other day. I guess we were the first to sign up for the free service. Thank you Yupapa!

meow
May 23rd, 2001, 10:11
LUCIFERRRRRRRRRRRR!

I ought to able to figure this out, but I'm stuck. :o
What I want is the users to be able to change the whole style sheet. It works fine, if I start with no style at all.

What I have now is this. front.css is the full style sheet and none.css just contains a fake rule. Works fine. But how do I set it up so the full CSS (front.css) is loaded with the page from start?



--- In HEAD ---
<?

# errors??

if ($style=="none" || $style==front){

## $style will be substituted for its value

echo "<link rel='stylesheet' href='$style.css' type='text/css'>";

}

?>

---- In BODY ----

<a href="test.php?style=none">Disable CSS</a><br>
<a href="test.php?style=front">Enable CSS</a>


One stupid cat :(

lucifer
May 23rd, 2001, 10:21
if (empty($style)){$style="front";}

at start of head script :)

meow
May 23rd, 2001, 10:33
meeeeeeeoooooooooooooooooooooooooow!!!!!

Lucifer, don't you ever leave this board. ;)
You are agood techer. Thank you again!

meow
May 23rd, 2001, 10:48
Teach - I'm curious. Why isn't there a double equal sign between the variable and it's value in this last one? Is this significant? :confused:

gyrbo
May 23rd, 2001, 13:09
Originally posted by meow
Teach - I'm curious. Why isn't there a double equal sign between the variable and it's value in this last one? Is this significant? :confused:
In the first one, it's a compair sign. If the two values are the same, it returns a 1, otherwise a 0. On the second one it declairs a variable, the asigns a value to a variable.

lucifer
May 23rd, 2001, 13:46
yup,

easy f**k-up

if ($fish=7){ do something } :(

not

if ($fish==7){ do something } :)

first one just sets $fish to 7 and does the thing

the second does the thing only if $fish has value of 7

meow
May 23rd, 2001, 13:52
I see. When testing conditions, use 2. Good to know.

meow
May 26th, 2001, 11:33
It's me again. :o

if (empty($style)){$style="front";}
Could I add another conditional statement that overrules the first? And says (in plain English):

"If the user comes from the specific page blah.html load other.css and this will overrule the first command (load front.css)"

That is, everyone will get front.css when they first enter except those that come from blah.html. They will get other.css instead.

Sorry to be such a pest.

lucifer
May 27th, 2001, 12:54
you could do



if ( preg_match( "/blah\.html/" , $HTTP_REFERER ) ){$style="other";}


if you put it after the 'empty' check it'll just override it

this does't work if the browser doesn't send a HTTP REFERER header

you could just hard code the link from blah.html to have ?style=other

meow
May 27th, 2001, 13:28
you could just hard code the link from blah.html to have ?style=other
Faeces I'm stupid! I see how it looks in the address field and still I don't...Grrrrrrr!

I'll try the other way. Seems more fun. Why wouldn't the browser send a HTTP REFERER header? Does that depend on the browser or - what?

Thanks! :):):)
(We have just invented a kinder, more devilish browser sniffer. ;) )

lucifer
May 27th, 2001, 22:17
Originally posted by meow

Faeces I'm stupid! I see how it looks in the address field and still I don't...Grrrrrrr!
is that the regular expression bit /somemeaninglesscrap/ worth using and not to hard to learn but you need a good tutorial


Why wouldn't the browser send a HTTP REFERER header?
when has a browser ever done what it should
HTTP REFERER is optional/not required

browsers not doing what they should example

if you are as claimed in your sig. using K-Meleon then my atavar is f**ked with the transparancy, though yours is OK maybe it's an alpha/index transparancy thing or just animation.

meow
May 27th, 2001, 23:51
Are you implying that I should read a book or tutorial on php? Why? I've got all I need here at fws. ;)
But if you know of a good online beginner's tutorial I'll listen.

Your avatar looks like a bleeding snowflake. The previous version didn't have full image support. Don't know about this one, but I haven't noticed that before. Maybe it's the animation? And I don't know what Peo has done, but the "submit"and preiew" buttons are totally gone in kmel. Has been there before. :(

lucifer
May 28th, 2001, 10:12
on K-meleon the submit/preview buttons are back again :)

it's got no file upload though :(

I'm sure someone as resourcefull as you can find a good tutorial ;)

meow
May 28th, 2001, 10:46
Lot's of them out there. That's the problem with everything in this world. You have to wade through the crap to get to the candy. :D

lucifer
May 28th, 2001, 14:56
not online but o'reilly's has a good reg expression chapter in perl programing worth a read if your in a bookshop.

sorry not much help :(

meow
May 28th, 2001, 16:14
Oh Regexp, I thought you were suggesting I should learn php and stop nagging you. ;)
Wow, what an handsome avatar. :D

lucifer
May 28th, 2001, 16:19
Originally posted by meow
I thought you were suggesting I should learn php and stop nagging you. ;)
you don't have to learn php it's intuitive ;) ;) ;)


Wow, what an handsome avatar. :D
better than the snow flake?

I hope to improve :)

meow
May 28th, 2001, 16:33
Sounds good. I was planning on trying to learn some Perl. But all this got me wondering if PHP perhaps is a better place to start for a dumber. I'll go hunting for some introductory stuff and some examples. I like to do a little trial and error before reading the book. Makes it easier to understand.

lucifer
May 28th, 2001, 16:48
depends what you want to do.

I learnt perl first and it is a useful language very quick and easy once you get the hang of it. However since I discovered that my server had php I started using that, mainly as sql intergration is so easy :)

I found php easy as it's very similar to Perl in my mind though the books will tell you that they are both based on C which I never really bothered with that much.

I've learnt php from the manual that comes with it. It's fairly basic and not as informative as you'd like but it's the way to learn what it does. I've since read a big thick book on it but it didn't really tell me anything new

I'm a believer in you use the best tool for the job -

I did a bit of JSP (java server pages) too but it's a lot of work for not much reward. OK you end up with industrial strength pages but I'm not doing anything that needs them.

start playing :)

meow
May 28th, 2001, 17:43
One can hurt oneself playing. I'll try to be brave. Got a soft start anyway. ;)
Sh*t! I just realized that my chamaeleon looks like a green cow. :eek:

lucifer
May 29th, 2001, 16:45
Originally posted by meow
Sh*t! I just realized that my chamaeleon looks like a green cow. :eek:

is that what it is :confussed: I should have spotted it it's about the only icon left on my desktop after the last sweep up :)

puDDs
May 29th, 2001, 23:00
You can do it with ASP. Just use an if statement combined with either a cookie (if you want it to last), or a session variable (if its ok if it reverts after).




<%

'Get Current Style from session variable
'Could be changed to used cookies easily
dim style
style = Session("style")

'Set to a default if session variable is not set
if style = "" then
style = "styleone"
end if

'See if user wants to change styles
'If so, change (or set) the session variable
dim newstyle

newstyle = Request.Querystring("newstyle")
if newstyle <> "" then
Session("style")=newstyle
end if

%>

<html>
<head>
<link rel="stylesheet" type="text/css" href="<%= style %>.css">
</head>
</html>

meow
May 30th, 2001, 17:25
Thanks puDDs (nice name!), but ASP isn't an option for me.