【问题标题】:Incrementing a $_GET variable by 1 if a url is clicked如果单击 url,则将 $_GET 变量增加 1
【发布时间】:2011-03-10 20:55:05
【问题描述】:

我该怎么做?

我有一个变量集

if (!isset($_GET['ago']))

我想在点击这个时将它加一

    if (isset($_GET['tod']) && $_GET['tod'] == 'overnight') {

        print ++$_GET['ago'];

    }

所以如果它被点击,我想要'http://xxxguide?tod=overnight

实际上看起来像 'http://xxxguide?ago=1&tod=overnight

每次点击“隔夜”时,“前”都会增加 1,所以

http://xxxguide?ago=2&tod=overnight http://xxxguide?ago=3&tod=overnight 等

【问题讨论】:

  • 改用$_SESSION 存储ago
  • 你想重定向页面还是什么?

标签: php url variables get


【解决方案1】:

在页面顶部的开头,在编写任何代码之前,写下以下行,不带任何空白字符(如空格或回车或制表符):-

<?php
ob_start();
session_start();
?>

现在到你的“if”块,并根据以下代码修改它:-

if (isset($_GET['tod']) && $_GET['tod'] == 'overnight') {
    $_SESSION['ago_counter'] = ++$_GET['ago'];
    header('Location: '.$_SERVER['REQUEST_URI'].'?ago='.$_SESSION['ago_counter'].'&tod=overnight');
    exit();
}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    • 1970-01-01
    • 2016-07-21
    • 2012-05-25
    • 2021-06-27
    相关资源
    最近更新 更多