Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Random back grounds.

Posted by SonnyZA (SonnyZA), 17 July 2005
hello ppl

Hope you all are fine. Especially you Graham.  

Was wondering. I want a website to rotate backgrounds on each refresh. So i took a code I got for rotating banners and i'm trying to convert this, so my website's background will change each time.

the code for the .js file, looks like this and is placed in my root directory:

Code:
var Quotation=new Array() // do not change this!

// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array.  Remember
// to increment the Quotation[x] index!

Quotation[0] = "<body background="http://toets.coolhost.za.net/tile1.gif" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">";
Quotation[1] = "<body background="http://toets.coolhost.za.net/tile2.gif" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">";
Quotation[2] = "<body background="http://toets.coolhost.za.net/tile3.gif" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">";
Quotation[3] = "<body background="http://toets.coolhost.za.net/tile4.gif" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">";
Quotation[4] = "<body background="http://toets.coolhost.za.net/tile5.gif" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">";



// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();


Now my line I insert in the body text look like this:

Code:
<script type="text/javascript" src="bground.js"></script>


What am I doing wrong?   Again, I'll apreciatte any help.

Posted by admin (Graham Ellis), 17 July 2005
Hi ... Javascript isn't really my "thing" ... but I have called up random images from PHP.   Not quite what you're looking for, but it may be close enough for you to adapt / adopt if you like the approach.

See ...
Sample Script (source)
Sample script (running)
Download of newsletter from Autumn 2004 where it's documented on pages 18 and 19

A random picture of Rome:



Posted by SonnyZA (SonnyZA), 17 July 2005
Hey Graham,

Thanks for the reply.
Firstly, can I use this with a HTML  page? This website is a HTML  page and I don't know anything of PHP.

Secondly: Can I use it to change the background of the page, which I normally used a jpg or .gif as well?

If I can use this with HTML, how do I go about in doing this? Where do I put in the code? And the pictures? Plus, I guess that with the background a different code must be inserted.  

Thanks again

Greets

Posted by admin (Graham Ellis), 17 July 2005
Here's the source of an HTML page that uses that previous PHP code:

Code:
<head><title>A demo of changing backgrounds</title></head>
<body background=/demo/rome.php4 text=red>
<h1>Tiled random background</h1>
This is a piece of red text over a tiled, random background.
</body>
</html>


I have a running copy on my website if you want to try it.

It will work with any HTML web page ... but the image script (the PHP) must be on PHP enabled web space ... in my example it's on the same server.   Although you're not familiar with PHP, you should know enough programming to see how you can change directory names, etc, to point to you own image library.

Finally, a general note about background images.   They should really use a limited range of colours so that the real web page that's drawn on top of them is actually readable.    That's an "aristic" thing and is clearly not the case with many of the images I happen to have in my demo directory that give an effect that's overpowering to say the least!

Posted by SonnyZA (SonnyZA), 17 July 2005
Thank you Graham for the rep;y, help and tips. I'm sure I'll get it right. I'll go and try, and I'll report back. Thanks again

Posted by SonnyZA (SonnyZA), 17 July 2005
Ok, I'm not that sure anymore. LOL.

Maybe I do need a bit of help. Just to make sure, I copy this .php file to the image directory along with the images as well as root directory. Still don't wanna work. I know I'm doing something wrong. Maybe path problem. I've changed the paths a few times, at the moment the php file looks like this:

Code:
<?php
header("content-type: image/gif\ncache-control: no-store\n");
$dir = "/images/tile";
$dh = opendir($dir);
$contains = array();
while ($content = readdir($dh)) {      
     if (eregi('jpg$',$content)) {                        array_push($contains,$content);      
     }
}
$which = rand(0,count($contains)-1);
$fname = "$dir/$contains[$which]";
$fh = fopen($fname,"r");
$data = fread($fh,filesize($fname));
print ($data)
?>


I've put the 2 .gif files in my "/images" directory and they are named:

tile1.gif
tile2.gif

It's on a php enabled server plus I put this code in the htm file.

Code:
<body background=/images/tile.php4 text=red> </body>

Ok, can you see where I do wrong? Please.   Forgive me if this is my stupidest question yet

Posted by admin (Graham Ellis), 17 July 2005
It looks like you have an absolute path (one starting with a "/") in you assignment to $dir in the second line.   You probably want a relative path in there - so it should probably start ../ or ../../ (note the extra dots) to take it up one or two levels relative to where the current script is.

Also ... the script is looking for file names enging in .jpg (that's what you're checking for in the while loop in the middle) but you have provided images in files ending in .gif.   My demo script worked with .jpg rather than .gif files ... you'll need to change the "jpg" to "gif" if you want it to work with GIFs.

Posted by SonnyZA (SonnyZA), 17 July 2005
Ok I see I missed that $jpg that I had to set to gif, I only changed the one in the first line. My images folder lay in my direct root, in my public_html and I've tried it with and without a " ./ "

Still nothing. Am I correct of renaming the php file to:

tile.php4

I've even tried:

tile.php

But to no avail

Posted by admin (Graham Ellis), 17 July 2005
(a) Are your sure that the system on which you are running the PHP script is PHP enabled?   The main web page doesn't need to be on such a domain, but the images do have to be.

Try setting up a page that contains just

<?php phpinfo(); ?>

and it should tell you all about the PHP installation

(b) I suggested ../ rather than ./   ...   ../ (two dots) means "in the parent directory" but ./ (one dot) means "in the current directory".   As you're already in the current directory, thi smeans that adding "./" in front of a file name won't make any difference at all!

Posted by SonnyZA (SonnyZA), 17 July 2005
Graham:

The server I used is one I rent for a reseller. (I'm doing web hosting now) and I did previously installed php software like e107 (cms)

I run that line anyways for the php info and here is some info I got.


=======================================

System  Linux mcevoy.myprivatedns.us 2.4.21-32.0.1.EL #1 Tue May 17 18:01:37 EDT 2005 i686  
Build Date  Jan 10 2005 22:13:09  
Configure Command  './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-xml' '--enable-bcmath' '--enable-calendar' '--with-curl' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-imap' '--with-imap-ssl' '--with-kerberos' '--with-mcrypt' '--enable-magic-quotes' '--with-mysql' '--with-openssl' '--enable-discard-path' '--with-pear' '--with-pgsql=/usr' '--enable-sockets' '--enable-track-vars' '--enable-versioning' '--with-zlib'  
Server API  Apache  
Virtual Directory Support Support  disabled  
Configuration File (php.ini) Path  /usr/local/Zend/etc/php.ini  
PHP API  20020918  
PHP Extension  20020429  
Zend Extension  20021010  
Debug Build  no  
Thread Safety  disabled  
Registered PHP Streams  php, http, ftp, https, ftps, compress.zlib  

=======================================

I also changed the path to " ../ " and still nothing. However...when I refresh the page, it does say in the taskbar :

Downloading picture: http://www.toets.coolhost.za.net/images/tile.php4

thanks again

Posted by admin (Graham Ellis), 17 July 2005
I used telnet to browse that URL and it says

Code:
HTTP/1.1 404 Not Found
Date: Sun, 17 Jul 2005 19:10:33 GMT
Server: Apache/1.3.33 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.10 FrontPage/5.0.2.2634a
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /images/tile.php4 was not found on this server.<P>
<P>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.
<HR>
<ADDRESS>Apache/1.3.33 Server at www.myprivatedns.us Port 80</ADDRESS>
</BODY></HTML>


which tells me that you have the PHP script in a different place on your server to the place that you've stated it's located in within your HTML.   (((Where is the .php script?   Is it in the images directory?   I'm guessing not, but you've included /images in the page that calls up the image)))


Posted by SonnyZA (SonnyZA), 17 July 2005
It's is under my "public_html/images/" directory. I also now put it under my root diirectory but still nothing. It's there alongside my 2x .gif files.

strange for me indeed. I even changed the extension to only .php and not .php4

Not that I know whats the difference.

It's getting late, and I don't want to keep you up. If we can't solve this, don't worry, tommorow is another day. I'll try a few hours longer still.

Posted by admin (Graham Ellis), 17 July 2005
Yeah ... I *am* just about done for the day (I'll be back, briefly, firstthing in the morning then each eveing during the week as I'm teaching away from home).   To step forward, try to find out the URL of the script and to get it to run directly (without the other HTML wrapper) as per my first example ... then add back in the surrounding page and background.   It's probably very close indeed.

Extensions ... .php v .php4 ... it depends on how the system is configured.   If you use the SAME EXTENSION that you used for the "phpinfo" test, it should be OK ... no need at all to change that!


Posted by SonnyZA (SonnyZA), 17 July 2005
Ok i'll play around a bit and let you know Thanks so much for your help thus far. Have a good night.

Posted by SonnyZA (SonnyZA), 18 July 2005
You know, I feel quite daft now. LoL. Still nothing I even tried inserting the direct paths of the full URL in the html file. Nothing. I would like to kick myself, but I can't  

If all else fails, I could PM you my FTP  details and if you have a change in your very busy schedule, you can have a look?  

I a test site so i can learn and use it on my web designs. If you can't I'll understand, i'll just give it more effort.

BTW, I ran that test as a file: test.php, but ran it again as: test.php4

Looks good.

Posted by admin (Graham Ellis), 18 July 2005
It's probably one of those things that's hard to spot ... then very easy once you HAVE spotted it  

Tonight and tomorrow night, I'm only on line from a hotel ... not really in a position to do much from here.  Home on Wednesday night; if you're not sorted by then I can have a look on Thursday.

Posted by SonnyZA (SonnyZA), 18 July 2005
Ok, sounds good. in the meantime I'll just fiddle with it and burn the server down or something..LoL.  

Its fun to learn anyways. I'll report back.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho