php script for rand between 2 images

i need an php script that "rands" between 2 images
main ideea ... i have 1.jpg and 2.jpg .. and at every refresh i want them changed
rares_dumitrescuAsked:
Who is Participating?
 
VoteyDiscipleConnect With a Mentor Commented:

<img src="<?= rand(1, 2) ?>.jpg" alt="A Random Image" />
0
 
Eduardo_PintoConnect With a Mentor Commented:
<?php
session_start();

if ( isset($_SESSION[rand]) ){
 if ( $_SESSION[rand] == 1 ){
  $_SESSION[rand] = 2;
 }
 else{
  $_SESSION[rand] = 1;
 }
}
else{
   $_SESSION[rand] = 1;
}
?>

<img src="<?= $_SESSION[rand] ?>.jpg" />
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.