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条)

报告相同问题?

悬赏问题

  • ¥15 Python动态规划:图2箭头指向的代码如何理解?太抽象了
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip