Forum Moderators: coopster

Message Too Old, No Replies

PHP or Java Script?

New User

         

brow

1:55 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



I was wondering if someone could tell me if there is any benefit in using a PHP script over Java Script to apply random images on my web page?

Thanks in Advance.

jatar_k

6:36 pm on Feb 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld brow,

if it is just for random images and you aren't referencing a database then one works as well as the other.

The only thing is users with js turned off but I don't imagine that will be a monster issue.

brow

8:31 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



I think the java script I have has something in it that actually sets a default image for people that do not have Java script enabled.

The only other draw back then would be that I have to actually put a php file on the server, meaning I would have to amend it every time I added or changed an image.

Thanks for your help.

matc

5:03 pm on Feb 25, 2004 (gmt 0)

10+ Year Member



Hi there

Not in line with the tile of the post but.....

I heard there is a random() function to mod_include.
[ssi-developer.net...]

Might help but check if its supported on your server first if you're interested in using it :)

cheers, ject

brow

6:16 pm on Feb 25, 2004 (gmt 0)

10+ Year Member



That is quite interesting.

Thanks! I don't think I will use it in this instance, but may well in future. I know nothing of SSI so it has definetly opened my eyes...

coopster

8:57 pm on Feb 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



To the best of my knowledge there is no random() function in mod_include [httpd.apache.org]. What you are seeing there is a (creative) use of the time, a variable and flow control.

That said, why not use the PHP include [php.net] function instead?

coopster

9:06 pm on Feb 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



And on another note...

The only other draw back then would be that I have to actually put a php file on the server, meaning I would have to amend it every time I added or changed an image.

Not true, brow. You could put all the images in a specific directory and let PHP handle that for you, without code modifications. You could open [php.net] the directory, read [php.net] the files, and populate an array from which you would randomly select an image.

Or, better yet, use a file upload script as opposed to FTP to upload the images to the directory. At the end of the upload process, update a text file that you keep in that directory that has a comma-separated list of the files in the directory. This would eliminate the need for the server to loop through a directory on every page call. It would open and read the text file instead. I'm not sure if this would be faster or not, but I would tend to think it would be, especially once your images directory gets more populated.

Just a couple more ideas/options for you to consider.

webadept

3:41 am on Feb 26, 2004 (gmt 0)

10+ Year Member



Just want to ditto Coopster's post here. If you use Javascript you will have to add code all the time, unless you know of a what to read directories with javascript.

You can do that with server side javascript ...
[faqts.com...]

as long as the directory you want to read is where the javascript files is at, but if you add a new directory, to keep things sorted out for you, then you have to add a new javascript as well.

Really it boils down to how dynamic this place you are creating is going to be. PHP does dynamic very well, Javascript is great for effects and things that happen on the browser.

My rule of thumb is if it deals with the information once it is in the browser (user clicks something or highlights something) then it is Javascript, if it is on the server and dealing with web page information PHP. If it is on the server and a utility, Perl.

But that's just me, and basically I'm lazy and don't want to work harder than I have too.

brow

9:28 am on Feb 26, 2004 (gmt 0)

10+ Year Member



Thanks for your help guys!

I like the sound of a file upload script... Where might I find one?

I am going to be using an image gallery called emalbum and content management (news) called Cutenews. To me it all seems very fragmented.

I am just thinking outloud, but surely I could randomise the images coming from the gallery to be shown on say my index page using another PHP file?

Can you point me in the direction of some good PHP tutorials so I am able to get my head round this? In an ideal world I would like to write my own gallery to do the above.

Thanks in advance: a very lost brow

coopster

2:26 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The Image Upload and Thumbnail Generator [webmasterworld.com] may get you started.

brow

3:29 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



Thats great.

Thanks for your help!