Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Random Picture Changer

  • 23-01-2005 11:03pm
    #1
    Registered Users, Registered Users 2 Posts: 884 ✭✭✭


    Lads,

    I am looking for a script that will change a picture everytime you visit my homepage. I want it to change everytime you refresh or visit but i dont want the same pic for first visit, i.e. start with pic1.jpg and then increment or whatever as users will visit the site and see the home page but not return there in that visit, that would mean they would see pic1.jpg everytime and not get a chance to change the pic as they dont return to that page. (i hope i am explaing that ok)

    I dont want to use a cookie or cache to record their last pic either.

    Is there anyway i could change the pic depending on the time, i.e. if it is 12.03 it shows pic3.jpg, if it is 07.56 then it shows pic6.jpg etc. So it will change depending on the minute or second if thats possible.
    I'd plan to have about 10-20 pics in the array.

    Can anyone help me out ??


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Got a preference on how its done? Javascript/PHP/ASP?


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Javascript could help. PHP will also do this.

    There's no way you can guarantee that someone will see a different picture every time, or that they won't see a certain picture twice, without writing something to a cookie. You could use sessions, but they won't be valid once the browser is closed.

    What you can do however, is make it random. Given a sufficiently large number of pictures, the chance of seeing the same picture twice is reduced.

    Any programming language will have functions for generating a random number. You just generate the random number, then use that number to decide which image to use.
    This page gives a good example of random numbers.

    So usign the above page's function, and you have say 50 pics in your directory, you could do:

    randomNum = rand(50)

    document.images[1].src = "http://wwww.mysite.com/images/gallery/" + randomNum + ".jpg"

    The only problem with this is that if someone has Javascript turned off in their browser it won't work. PHP would be a better solution.


  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    Got a preference on how its done? Javascript/PHP/ASP?

    Sorry ... should have mentioned that ...

    It is all html so javascript would be the best for it i'd say !!


  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    seamus wrote:
    The only problem with this is that if someone has Javascript turned off in their browser it won't work. PHP would be a better solution.

    Oopps ... i forgot about that, how do you do it with PHP ??


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Cork Skate wrote:
    Oopps ... i forgot about that, how do you do it with PHP ??
    In exactly the same way as in JavaScript, except naturally in a slightly different language (PHP) and executed by the server rather than the browser. The only other consideration is the server's timezone, should you want images to be time dependant.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 884 ✭✭✭Cork Skate


    Lads, i am a total php virgin

    i am trying to create a page with this ....
    <html>
     <head>
      <title>PHP Test</title>
     </head>
     <body>
     <?php echo '<p>Hello World</p>'; ?>
    </body>
    </html>
    

    saving as test.php and it wont open in IE ... am i doing something wrong (icon is a white page with an IE e on it, not normal icon if that helps)


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Cork Skate wrote:
    Lads, i am a total php virgin
    Start with the basics. Read the following three in order and also do the tutorial in the last. The you will be in a position to more questions or even just do it yourself:

    http://www.wdvl.com/Authoring/Scripting/WebWare/Server/
    http://www.php.net/manual/en/introduction.php
    http://www.net-language.com/workshops/Default.asp?workshop=21


Advertisement