Bit of a Pickle :/

by 4 replies
5
Firstly, thank you for helping me with my Pickle

Let me start off by trying to explain what I am trying to do:

Problem is I am counting the clicks in PHP, and stuck trying to call the Javascript function after the PHP calls the counting page, then reloads the index(<--- This is when I need that function called...)

I also want to use localStorage in Javascript to keep the element(button) hidden after it is clicked, even if they reload the page, can anybody give me some examples on that one also please?

Here are my script/s:

root/index.php:

Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include 'includes/functions.php'; ?>

    <script type="text/javascript" src="scripts/jquery.js"></script>

    <script type="text/javascript" src="scripts/javascript.js"></script>
    
</head>
<body>

    <div id="button">
        <a href="join.php?click=1" onclick="hideButton()">JOIN HERE</a><br>
        <?php echo $get_count;?> people have joined simply by clicking the link above!
    </a>
    
</body>
</html>
root/join.php:

Code:
<?php

$click = $_REQUEST['click'];
        
$file_location = 'clicks.ini';
$update_hits = file($file_location);

$update_count = ($update_hits[0] + 1);
$get_file = $file_location;
$handle_file = fopen($get_file, 'w');
$return_data = "$update_count";
fwrite($handle_file, $return_data);
fclose($handle_file);

echo '<meta http-equiv="refresh" content="0; url=index.php">';

?>


root/
includes/functions.php:

Code:
<?php

//Click Data
$file_location = 'clicks.ini';
$get_hits = file($file_location);
$get_count = ($get_hits[0]);

?>
root/scripts/javascript.js:

Code:
//Hide Button
function hideButton() {
    $('#button').hide();
}
Thanks in advanced
#programming #bit #pickle
  • Ajax.

    Use an ajax call to signal the PHP script to do what it needs to do, then hide the button without reloading the page.
    • [ 1 ] Thanks
    • [1] reply
    • Thank you for your input.

      Although I am treading on thin ice with PHP and AJAX at the moment as I have not really worked with them properly until now.

      Could you possible show me a bit of code so I can understand what I need to do?


      Thanks in advanced.
      • [1] reply
  • Yeah, jQuery .ajax() would be a good option.

    BTW, there is NO need to use HTML5 Local Storage for a simple "function" that hides the button. Local Storage is not made for those simple stuff.

    Using cookies is really one of the common options.

Next Topics on Trending Feed