Random Quote Version 3.1
Posted on September 5, 2005
{{LEARN PHP HERE}}
Version Update: 4.1 exists here
This random quote script is based on earlier versions and is the product of all of the great suggestions I have received. Included in this script are a number of options including:
- Random Quotes being pulled from a flat file database.
- Ability to randomly pull from multiple flat file databases.
- Ability to set a variable which will control how often a new quote is displayed – Every time the page is loaded, every minute, every hour, once a week, etc. This is done by setting a cookie.
View this script in action (no cookie) here
View this script in action (one hour cookie) here
Download the Random Quote script here (16kb) Current Download Count: 4796
Questions: Email Me
- A common question is how to remove the link if you don’t want to link to the reference of the quote. Here is a TXT file with an explaination of the necessary changes.
- Here is an example of how to use a Style Sheet with the random quote script. View it in action.
Filed Under PHP | 14 Comments
Leave a Comment
If you would like to make a comment, please fill out the form below.

Your script is great I like it but if one has no URL for quote link what to do
I added a TXT file with an explaination. Thanks for your question.
Thanks for clarification
I am looking for a database of quotes (wisdom, inspirational) that does not include quotes from the Bible to link into my website that is underconstruction. Ideas?
Really Cool! php script
Is there a way to have the quote change every 3 minutes?
I have it set on 1 and if the code line is:
setcookie(“quoteNum”, $ranNum, time()+60*60);// One Hour
then should i set it to
setcookie(“quoteNum”, $ranNum, time()+60*3);// for 3 minutes
However, the quote is showing but it is not changing after 3 minutes. Also, i have it in a frame so i guess maybe that’s the problem?
Is there anything i can change?
Anyway, awesome script, thank you.
There is a nuance between what is meant by the code in this script and what you are trying to do.
The code I wrote forces a quote to remain on the page each time the page is loaded until the set duration expires. When the cookie expires and the page is reloaded, the random quote generator randomly grabs another quote and displays it.
What you describe is a desire to force the quote to change on a set interval. This is better served by JavaScript as JavaScript can update on a page without having to reload the page.
The two seem similar but are different at the foundational level. (force quote to stay vs. force quote to change)
When I get some time, I will work on a JavaScript version to change it into a “change on interval” style script.
As for the code change to set to 3 minutes, you should order the math 3 * 60 not 60 * 3 it is the same math, but in the code 24*60*60 means 24 hours because you work backwards. 60 seconds * 60 minutes = 1 hour * 24 = 24 hours. The way you have it reads 3 seconds times 60 minutes when you mean 60 seconds * 3 minutes.
Hi, this is a great script and very usefull with lot of explanations. However, it would be great to design a board allowing to insert new data into the .db file. In this way, a newbie could insert himself and actualize his website ? Isn’t it a good idea ?
[Sorry - please disregard of my last comment on the previous script-page. I posted that before I followed this link. ] Wow – exactly what I was looking for. I am excited to try this out. Thanks a lot and God bless!
/anders
Hi,
Just downloaded your script haven’t tried it as my domain name is resolving.
Questions:
(1) Instead of a short quote, can it display a long one, one that takes almost a half a page?
(2) With this script, will the same quote stay on my page for 24 hours, then 24 hours later it shows another one (even if the visitors clears their cookies or refreshes their page)?
Thank you in any case for this nifty script!
Kait
my brother is a pastor, and i am going to be making a site for his ministry. he’ll LOVE the ability to have bible passages.
Hi – I downloaded your script. Have a problem with it. When you select displaying a quote every 24 hours or every 7 days, the script bombs. Could you take a look at it?
Thanks!
I am trying to embed the quotes in the footer of another page in my site. I no almost no knowledge of PHP scripting, I’m sorry. If you could tell me the code to write on my other pages that would be great. Thanks.
eBus: Do you have PHP on your webserver?
yes, my site is all php based. i’m just really not educated in the code so i’m not sure exactly what snipit of code to past on other pages.