即使在下次访问时,点击时也会使按钮消失


make button disapear when clicked even when visited next time

我有一个问题,我正在制作一个带有按钮的网站。问题是,我只想让访问该网站的用户按下一次。因此,当用户刷新或返回时,就不可能再按它了。

我认为我应该使用PHP和AJAX的组合,但不幸的是,我还不够好,无法将其组合在一起。希望这里有人能把我推向正确的方向:)

html代码:

    <form action="" method="POST">
    <input id="banana_button" type="submit" name="button_press" value="Add banana's!">
</form>

javascript:

$('input[name="button_press"').click(function(){
        $('#banana_counter_text').append($banana+1);
        $(this).attr('disabled',true).css('width','180px').attr('value','thanks for adding a banana');
    });

我想得到的是,当他们下次访问时按下按钮时,他们不会看到按钮。这可能吗?我怎么才能做到最好呢。我希望你们能帮我

更新:

在过去的几天里,我一直在努力解决这个问题,结果我成功了。我正在使用具有自定义名称的session_cookie。每次加载网站时,它都会检查cookie是否可用,如果不可用,就会显示按钮。否则将删除整个按钮。

代码如下:

PHP

//this is what checks everytime if the cookie is set
    if (isset($_COOKIE['banana_added'])) {
        //code for disabling the button 
    }
//this is what makes the cookie and checks if the submit button is pressed. 
//because people where wondering how the data is stored. It is just a simple XML file
    if(isset($_POST['buttonsubmit'])){
        /*when submit is pressed */
        session_name("banana_added");
        session_start();
        $xml = simplexml_load_file('../banana.xml');
        $prev_count = $xml->banana_count;
        $new_count = $prev_count +$_POST['buttonsubmit'];
        echo $prev_count;
        echo $new_count;
        $xml->banana_count = $new_count;
        file_put_contents('../banana.xml', $xml->asXML());
        header("location:../landing.php");

谢谢大家的帮助。我不知道该如何关闭这个线程?这是这个特定问题的解决方案

为了记住这个更改,您应该将该值放入COOKIE/SESSION或DATABASE中。当然,第二种变体更可取。比方说,在这个例子中,您有一个名为buttons的表,其中有一个类型为tinyint的列"checked"(接受值0和1),默认值为0。

在你的html中,你应该这样做:

<button <?php ($thisButtonQuery->checked == 'checked')? 'disabled' : '';?>>button text </button>

问候,我希望我解决了你的问题!:)

过去几天我一直在努力解决这个问题,结果我成功了。我正在使用具有自定义名称的session_cookie。每次加载网站时,它都会检查cookie是否可用,如果不可用,就会显示按钮。否则将删除整个按钮。

代码如下:

PHP
//this is what checks everytime if the cookie is set
    if (isset($_COOKIE['banana_added'])) {
        //code for disabling the button 
    }
//this is what makes the cookie and checks if the submit button is pressed. 
//because people where wondering how the data is stored. It is just a simple XML file
    if(isset($_POST['buttonsubmit'])){
        /*when submit is pressed */
        session_name("banana_added");
        session_start();
        $xml = simplexml_load_file('../banana.xml');
        $prev_count = $xml->banana_count;
        $new_count = $prev_count +$_POST['buttonsubmit'];
        echo $prev_count;
        echo $new_count;
        $xml->banana_count = $new_count;
        file_put_contents('../banana.xml', $xml->asXML());
        header("location:../landing.php");

谢谢大家的帮助。这就是这个特殊问题的解决方案