2012-11-09 31 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