dongsui0929 2011-09-28 23:17
浏览 43
已采纳

PHP链接点击效果

I have one question which is somewhat two-parted (though the parts go hand in hand). I've started picking up PHP, and I wanted to do two things when an image is clicked.

I want the click to

  1. Increment a session variables, say $_SESSION['entry'].
  2. Reload the current page (say index.php).

How should I go about this?

To be clear, I'm not asking for someone to code this for me, I'd just like to be pointed in the right direction because I'm not too sure what the best way would be.

  • 写回答

5条回答 默认 最新

  • doujianzi8521 2011-09-28 23:27
    关注

    Well, anchor links "reload" the page if the href points to the same page. So, all you need to do is tell PHP you want to increment the session variable. You could use a GET variable to do this:

    <a href="index.php?increment=true">Increment the counter</a>
    

    And then in your index.php:

    if (isset($_GET['increment']) && $_GET['increment'] == 'true') {
      $_SESSION['counter']++;
    }
    

    This assumes you've already initialized the session variable counter at some point. You can check out the wonderful PHP docs to explain the functions used above if you aren't familiar with them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?