Hey guys, wondering if you could help me with these two bits of code.
What I'm trying to do is count how many clicks a link has been clicked, then when it has been clicked x amount of times, it echos 'test'
Now the code below does that, but I've used a session, so it currently only counts when the page is refreshed.
<?php
session_start();
($_SESSION['count']) ? $_SESSION['count']++ : $_SESSION['count'] = 1;
if ($_SESSION['count'] % 5 == 0)
{
echo "test";
}
?>
Is there anyway to get this to apply only when the link below has been clicked:
<a href="index.php?act=generate_quotes&cb=<?php echo time();?>" class="main_control">Generate</a></p>
So when that link has been clicked it THEN begins counting? I've not really used sessions before so count someone maybe show me how this would be done?
And this may help:
The link I want to apply it to is calling the following function:
<?php
if($_GET['act'] == "generate_quotes") {
$con = mysql_connect("*", "*", "*");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("quote", $con);
$result = mysql_query( ' SELECT * FROM `quote` ORDER BY RAND() LIMIT 0,1 ' );
while($row = mysql_fetch_array($result))
{
echo '' . $row['q_quote'] . '';
}
mysql_close($con);
} else {
echo "<img src='img/vpbgt.png' alt='hello'>";
}
?>
Thanks for any info.