HOME       >>       General Discussion

Changing Background Color In Php usefull for templating.


sxyloverboy

Tutorial on how to change background color with PHP

 

 

I will be descibing to similiar ways that you can change the background color of your website with php and leave it at that till the user changes it again. We are going to do this with CSS. You can either have your cSS info on your page or in a spereate document. The first thing youll have to do is decide if your going for the linked stylesheet or directly on your page. IF you link it you'll need to have this code in you <head> </head> tags.

<style type="text/css"><?php include ("style.php") ?></style>
This isnt actualy real linking because i dont think you can link css stylesheets that end in .php. Anyways now were going to the read core of this thing. make your style.php file in the same folder where you have your index file or however you call it and put this code in it.

/* CSS Document */<?php$colour=$_GET["bg"];?>body { background:#<?php echo $colour ?>; }/* and any other style stuff you want to have */
Now back to the page where you want the background changeing to go on. This is going to be the link that you have
<a href="?bg=000000">Black</a>
if you want a black background. now you can change 000000 to anyof the RGB color that we use in the web.

 

The thing is right now the persons gonna go back to haveing white as their background color if they click any link other than that link for the balck background. so what your going to have to do is. Add a "&bg=<?php echo $bg; ?>" to the end of all of your links. that way it always tells it what the color for the background is. and you can also type in background colors into the url itself. so if you type in http://ww38.yoursite.com/index?bg=FF0000 your going to have a red background.

 

Now using this method you can change your whole color scheme of your website with one link and have your visitors choose how they like to have it, just remember to use diffrent variables each time. it could be a for background b for text color c for link colors and so on.

 

So then guys and gals. Happy Coding. If you have any question feel free to ask me and ill see if i can help.

 

And Merry Xmas and Happy New Year too. Wheee. hahaha


DreamCore

Nice I have never tryed to use the function "change color" in php. I have only used it in javascript and html.


master_bacarra

The thing is right now the persons gonna go back to haveing white as their background color if they click any link other than that link for the balck background. so what your going to have to do is. Add a "&bg=<?php echo $bg; ?>" to the end of all of your links. that way it always tells it what the color for the background is. and you can also type in background colors into the url itself. so if you type in http://ww38.yoursite.com/index?bg=FF0000 your going to have a red background.

 


but if you're going to use "../index.php?bg=FF0000" in the above statement, anyone can change it, by just typing a different color in hex. that could mess up the entire design of the webpage. what if i don't want the users to change the page's colors directly from the url. instead i want them to choose from different color schemes that is specified in my web page.

Tyssen

but if you're going to use "../index.php?bg=FF0000" in the above statement, anyone can change it, by just typing a different color in hex. that could mess up the entire design of the webpage. what if i don't want the users to change the page's colors directly from the  url. instead i want them to choose from different color schemes that is specified in my web page.

In that case you should test your $_GET against an array of permissible values and only execute the script if the value passed from the querystring is in the array.

iGuest

chang background colour

Changing Background Color In Php

 

How can change a background and text colour. Please help me about this metter.

 

-reply by Mubashir Malik


iGuest

where to but a link

Changing Background Color In Php

 

It seems as if the link is to insert the picture but want to know where to write the link code?

 

-reply by brenda



VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.