I have a code which I want to run with a wordpress site, this is working fine on simple and regular websites which is not cached but following php code is not working in cached website, which wp-rocket plugin or auto optimized plugin is installed, unfortunately I can’t remove those plugin, please help me also I can’t use javascript…

<?php 
if(!isset($_SESSION)) 
    { 
session_start();
    }
   ?>


<?php
if(isset($_SESSION['test']))
{
 if($_SESSION['test'] == 0)
 {
  $_SESSION['test'] = 1;
    ?>
 <!----place your Second ads here--->




    <!----Second ads end here-->
 <?php
 }
    else
 {
  $_SESSION['test'] = 0;
  ?>
 <!----place your First ads here--->




    <!----First ads end here-->
  <?php
 }
}
else
{
 ?>
<!----place your first ads here  this is default ads-->

 <!----First ads end here-->
<?php
$_SESSION['test'] = 0;
}
?> 

As you can see that I want to swap ads on every refresh of page.

Read more here: How to change session variable 0 and 1 on each page refresh


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: