php链接到2件事

时间:2012-11-09 16:25:01

标签: php hyperlink href

有没有办法在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>

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

2 个答案:

答案 0 :(得分:2)

当然。

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

答案 1 :(得分:0)

执行此操作的最简单方法是使用执行操作的页面,然后重定向用户。例如:

<强> /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命令时,您将收到一条错误消息。