Image only seen once

Discussion in 'PHP' started by MajHate, Aug 15, 2009.

  1. #1
    Hello,

    I am trying to come up with a way so a series of random images will only appear once using sessions. I've been struggling with this for awhile and I just can't figure out how to do this.

    so maybe like when an Image first showed up I would have $_SESSION[$random_image] = 1; //1 representing that it has been viewed

    However I don't know where to go from there, any ideas?

    Thank You!
     
    MajHate, Aug 15, 2009 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    if(empty($_SESSION['in_progress']))
    {
       $_SESSION['in_progress'] = 1;
       $_SESSION['images'] = generate_images();
    }
    
    if(count($_SESSION['images']) > 0)
    {
       work_with(array_pop($_SESSION['images']));
    }
    Code (markup):
     
    joebert, Aug 15, 2009 IP
  3. alons

    alons Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    joebert your script is almost right
    You can try this

    
    $list = array();//Your list of files
    
    foreach($_SESSION['shown'] as $v){
    unset($list[$v]);
    }
    
    //Then select a random file
    $toshow = current($list);
    $_SESSION['shown'][$toshow] = $toshow; //Mark as shown
    
    Code (markup):
     
    alons, Aug 16, 2009 IP