<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views']=$_SESSION['views']+1;
else
$_SESSION['views']=1;
echo "Views=". $_SESSION['views'];
echo '<br>'."<a href='destroy.php'>Set Counter1</a>";
?>
the above code was maintaining a counter, each time when user will refresh page it will increment. i want to do same work but with javascript but can’t find anything online help plz
We must first figure out what exactly are you trying to achieve. JavaScript runs in the client’s browser, so it’s not able to alter the $_SESSION in any way on your server, all by itself. If you wish to keep this counter only on the client side, try setting a cookie via JavaScript. Another option would be to keep storing the counter on the server session and incrementing it via AJAX. The problem with things that rely on JavaScript to work is that they are not reliable, because the clients can always choose to disable JavaScript. Maybe a better option would be to embed an iframe which targets the PHP script that increments the counter…