【问题标题】:php link to 2 thingsphp链接到2件事
【发布时间】:2012-10-30 00:02:23
【问题描述】:

php有什么办法可以有一个链接,当用户点击链接时,他们会调用一个函数,然后在调用该函数后立即将用户重定向到另一个网页。

$acceptEmailInvite; //append this url to the url in the link
if($app[UID]) {
    //how do I have a link connect to two redirects?
    $acceptEmailInvite = '/idx.php/store/accept/'.{$org['id']}; //link to this first
    $acceptEmailInvite = 'getLink?org='.$D['bta']; //then link to this
}

<a href="<?php echo $C['tdURL'].$acceptEmailInvite; ?>">Accept the invitation for: <b><?php echo $D['referer']; ?></b></a>

编辑:我的意思是这两件事仅在单击链接时发生。因此,除非单击链接,否则不应重定向用户。对困惑感到抱歉。

【问题讨论】:

    标签: php hyperlink href


    【解决方案1】:

    当然。

    <?php
        foo();
        header("Location: http://example.com/");
        exit();
    

    【讨论】:

      【解决方案2】:

      最简单的方法是创建一个页面来执行操作,然后重定向用户。例如:

      /idx.php/organization/accept/

      <?php
      // Get your ID's, presumably from the URL
      
      // Accept the invitation
      acceptinvite($org['id']);
      
      // Use header to redirect the user when you are done
      header("Location: getBuzzed?org=".$D['betacode']);
      exit();
      ?>
      

      您的链接如下所示:

      <a href="'/idx.php/organization/accept/'.{$org['id']}; ">Accept the invitation for: <b><?php echo $D['referer']; ?></b></a>   
      

      .. 但用户会看到自己直接转到getBuzzed...

      您可以在 Google 或 Facebook 上看到此功能的实际应用。如果你 google StackOverflow.com,结果中的链接实际上指向这里:

      http://www.google.com/url?sa=t&rct=j&q=stackoverflow&source=web&cd=1&cad=rja&sqi=2&ved=0CCsQFjAA&url=http%3A%2F%2Fstackoverflow.com%2F&ei=ii-dUKaiMc_Psgad8oGYBA&usg=AFQjCNERidL9Hb6OvGW93_Y6MRj3aTdMVA

      Google 使用此页面来跟踪谁点击了该链接,并在此链接存在危险时提醒您。

      重要 带有header 命令的页面不得回显任何内容。如果它显示任何内容,那么当您尝试使用header 命令时会收到错误消息。

      【讨论】:

      • ohhhhh,我认为应该这样做。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多