2012-11-09 33 views
0

有没有什么办法在PHP中有一个链接,以便当用户点击链接时,他们调用一个函数,然后立即调用该函数后,用户被重定向到另一个网页。php链接到2件东西

$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

当然。

<?php 
    foo(); 
    header("Location: http://example.com/"); 
    exit(); 
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> 

..但用户将看到theirself直接去getBuzzed...

您可以在Google或Facebook上查看此功能。如果谷歌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

谷歌使用此页面来跟踪谁点击了链接,并提醒你,如果这个链接是很危险的。

重要 页面与header命令必须不回任何东西。如果显示任何内容,则当您尝试使用header命令时,您将收到错误消息。

+0

ohhhhh,我认为这应该做到这一点。谢谢! – BrettG