Jump to content
xisto Community
Sign in to follow this  
sxyloverboy

Changing Background Color In Php usefull for templating.

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.