A Conversation for Use PHP to get a random background colour for a website

Peer Review: A891506 - Use PHP to get a random background colour for a website

Post 1

R'win

Entry: Use PHP to get a random background colour for a website - A891506
Author: R'win - U209791

A tutorial for creating a fairly simple PHP script for a random background colour on a website.
Both of the final scripts should work, as long as the server understands PHP


A891506 - Use PHP to get a random background colour for a website

Post 2

There is only one thing worse than being Gosho, and that is not being Gosho

The content of this entry is not something I have a great deal of knowledge of, but the writing and layout look excellent smiley - ok


A891506 - Use PHP to get a random background colour for a website

Post 3

R'win

Thanks smiley - smiley
I tried the two final scripts and they both work. (I actually made the first script earlier this year for one of my websites, and the second was an idea I had when I decided to write the entry.)


A891506 - Use PHP to get a random background colour for a website

Post 4

HappyDude

It might be worth mentioning that not all web-host support server side scripting.


A891506 - Use PHP to get a random background colour for a website

Post 5

HappyDude

oops, first para don't know how I missed that smiley - erm


A891506 - Use PHP to get a random background colour for a website

Post 6

xyroth

while I don't see anything particularly wrong with the article, I can't actually see any good reason why you would want to serve up random background colours.

it might make a good php tutorial (but I don't know the language well enough to tell if it does), but it does seem rather a pointless thing to do.

considering just about all of the external links are to the php website, wouldn't it be better to try and get the tutorial added there?


A891506 - Use PHP to get a random background colour for a website

Post 7

The Researcher formally known as Dr St Justin

True, you might not want to serve up random background colours, but the same scripts could be used for random colouring of *any* html entity, if you so wanted.


A891506 - Use PHP to get a random background colour for a website

Post 8

Tango

Nice entry, well done! You might want to mention about not all servers using PHP in the last para as well, as a disadvantage, at the moment it is a very one sided comparision.

Tango


A891506 - Use PHP to get a random background colour for a website

Post 9

The Guy With The Brown Hat

Maybe I'm being pedantic here, but for example 2b, wouldn't it make more sense to put all the colour values in an array to start off with, rather than assigning them to individual variables and then stuffing them in the array.

For example:

<?php

$colours = array( 1 =>
"#ffffff",
"#ffff99",
"#00ccff",
"#66ff99",
"#ffcc00",
"#d7ebff",
"#ccffcc");

$max = count($colours);

$number= rand(1,$max);

$bgcolour = $colours[$number];

echo ("");

?>

(Btw in your 2b, $bgcolour still uses the 2a-style $cN assignment. I'm guessing this was just a typo!)


A891506 - Use PHP to get a random background colour for a website

Post 10

R'win

It wasn't a typo, and it works, but now that you mention it the array could have been used a bit more than it was.
Still it does what it's supposed to...


A891506 - Use PHP to get a random background colour for a website

Post 11

R'win

It can actually be used to do random *anything* not just colours, it would just need a little editing...


A891506 - Use PHP to get a random background colour for a website

Post 12

R'win

Tango, good point. I'll add that as a disadvantage


A891506 - Use PHP to get a random background colour for a website

Post 13

The Guy With The Brown Hat

Ok .. but if it wasn't a typo, then there is absolutely no point in having the array there. It adds confusion.

You've written a nice introduction to showing people how to integrate PHP into a webpage - but I really think you should tidy the code up a bit.


A891506 - Use PHP to get a random background colour for a website

Post 14

R'win

The array is used to find the number of colours for the upper limit of rand(). Had I thought at the time I could have used the array to find a random entry in it, but I don't see anything wrong with how it is at the moment


A891506 - Use PHP to get a random background colour for a website

Post 15

The Guy With The Brown Hat

It's still a waste of an array - after the while loop has terminated, the upper limit is ($n-1)


A891506 - Use PHP to get a random background colour for a website

Post 16

Mikey the Humming Mouse - A3938628 Learn More About the Edited Guide!

Although you say that the entry assumed the reader knows something about PHP already, I really think your first paragraph should have at least a sentence or two explaining what PHP is, what the letters stand for, etc.

smiley - mouse


A891506 - Use PHP to get a random background colour for a website

Post 17

R'win

Good point.
I've quoted such a passage from http://www.php.net


Congratulations - Your Entry has been Picked for the Edited Guide!

Post 18

h2g2 auto-messages

Your Guide Entry has just been picked from Peer Review by one of our Scouts, and is now heading off into the Editorial Process, which ends with publication in the Edited Guide. We've therefore moved this Review Conversation out of Peer Review and to the entry itself.

If you'd like to know what happens now, check out the page on 'What Happens after your Entry has been Recommended?' at EditedGuide-Process. We hope this explains everything.

Thanks for contributing to the Edited Guide!


Congratulations - Your Entry has been Picked for the Edited Guide!

Post 19

Spelugx the Beige, Wizard, Perl, Thaumatologically Challenged

Congratulations R'win! smiley - bubblysmiley - bubblysmiley - bubblysmiley - bubbly

spelugx -- _scout_


Congratulations - Your Entry has been Picked for the Edited Guide!

Post 20

Tango

Took some time, but well done! smiley - smileysmiley - bubbly


Key: Complain about this post