Reputation: 853
Is there any way in php to have a link so that when the user clicks on the link, they call a function and then immediately after calling the function, the user is redirected to another webpage.
$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>
EDIT: I meant that these two things happen only when the link is clicked. So the user should not be redirected unless the link is clicked. Sorry for the confusion.
Upvotes: 0
Views: 112
Reputation: 3338
The simplest way to do this is to have a page that performs the action, then redirects the user. For example:
/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();
?>
Your link would look like this:
<a href="'/idx.php/organization/accept/'.{$org['id']}; ">Accept the invitation for: <b><?php echo $D['referer']; ?></b></a>
.. but the user would see theirself go directly to getBuzzed...
.
You can see this functionality in action at Google or Facebook. If you google StackOverflow.com, the link in the results actually points here:
Google uses this page to track who has clicked on the link, and alert you if this link is dangerous.
Important
The page with the header
command must not echo anything. If it shows any content, then you will get an error message when you try to use the header
command.
Upvotes: 0
Reputation: 943207
Of course.
<?php
foo();
header("Location: http://example.com/");
exit();
Upvotes: 2