PDA

View Full Version : Help needed with 'Random Quotes' Script


Xko
02-08-2005, 04:30 PM
Hey...

I am trying to use a Random Quotes Generator Script from www.liquidfrog.com

The instructions i have followed (to the letter i might add!) are as follows...

(1) Unzip the distribution file to your local PC.

(2) Create a directory on your web server root and call it randomquotes.

(2) Upload codelock.php config.php, thequotes.txt and randomquotes.php to the randomquotes directory you just created.

(3) Chmod the randomquotes directory to 777.

(4) Edit the config.php file to suit your needs using notepad or something similar and save the file back to the server (a full explanation of the variables is given in the file).

(5) Include randomquotes.php in the page where you want it to appear. To do this use the lines below:

<?php
include('http://www.yoursite.com/randomquotes/randomquotes.php');
?>

(6) That's all.

Now i have done all that (and changed yoursite.com to my site address etc) yet the script does not work on my index.html page (here) (http://www.blme.org.uk). The 'quotes' should appear under the time and copyright thing at the bottom (for now anyway).

Can anyone shed any light to where i may have gone wrong? :confused:

(Thankfully no mysql database stuff is involved here - for info). :)

Acid
02-08-2005, 04:34 PM
Just use this instead:

<?php

$quote[1]="This is quote 1";
$quote[2]="This is quote 2";
$quote[3]="This is quote 3";
//and so on

$random = rand(1, count($quote));

echo "$quote[$random]";

?>

Xko
02-08-2005, 04:45 PM
Forgive my very basic php programming skills, but will that produce a 'random' quote everytime?

Oh and cheers for the fast response! :)

delinear
02-08-2005, 04:47 PM
Unless your server is set up to parse .html files as though they were php files, having an index.html won't work. Everything inside the <?php ?> tags will be ignored. You need to rename your page extensions from .htm/.html to .php.

Xko
02-08-2005, 04:49 PM
Hmmm ok, so if i rename index.html -> index.php it may work?

But when you type in the address www.blme.org.uk will the first page it goes to be the index.php?

Acid
02-08-2005, 04:59 PM
That would depend on the setup of the server but normally yes it will.

Xko
02-08-2005, 05:02 PM
Well would you look at that!

Rename to index.php and boom! it's working!

So could you explain the 'parse .html files' post that delinear mentioned?

Thankyou!!! :thumbsup:

marek_mar
02-08-2005, 05:58 PM
Here's an alternative:

<?php

$quote[]="This is quote 1";
$quote[]="This is quote 2";
$quote[]="This is quote 3";
//They get numebere automaticly anyway

$random_quote = $quote[array_rand($quote)];

echo $random_quote;

?>

Not a big deal. It's just to show that PHP has a function for getting a random value from an array.

delinear
02-08-2005, 07:06 PM
Well would you look at that!

Rename to index.php and boom! it's working!

So could you explain the 'parse .html files' post that delinear mentioned?

Thankyou!!! :thumbsup:

The web server can be set up to treat any page ending with .htm or .html as a .php file, which basically achieves what you've done above but without having to rename all the file extensions on the site. This doesn't break your html files it just saves work renaming files and allows you to have the .htm extension.

Chances are though that your webhosts won't enable this on a per-account basis so unless you have direct control over the server (or a VPS or something similar) you won't be able to do this, but you could always ask your hosts and see what they say :)

Kurashu
02-09-2005, 12:03 AM
Or use a htaccess