Reputation: 301
How do I create a link that sends the user to another page which is then diverted to another page associated with the link?
I would like to create a list of html URLS that as any one of them is clicked, it sends the user to an intermediary page, which asks the user whether they agree to the terms and conditions. If they do they are diverted to that page corresponding to that link they clicked. Similary to this diagram.
Link 1 ==> Intermediary Page ==> Page 1,
Link 2 ==> Intermediary Page ==> Page 2,
Link 3 ==> Intermediary Page ==> Page 3,
Link 4 ==> Intermediary Page ==> Page 4,
Link 5 ==> Intermediary Page ==> Page 5
I do not know what process it called. I intend to use HTML and PHP.
Upvotes: 2
Views: 14545
Reputation: 2974
HTML
<a href="inter.php?target=1">Some page</a>
<a href="inter.php?target=2">Some page</a>
<a href="inter.php?target=something_else">Some page</a>
PHP: inter.php
<?php
session_start();
$link='#';
switch($_GET['target']) {
case 1:
$link = "http://nexttarget.com";
break;
case 2:
$link = "http://nexttarget2.com";
break;
case "something_else":
$link = "http://nexttarget3.com";
break;
}
$_SESSION['prev_link'] = "http://source_url";
?>
<form action="<?php echo $link; ?>" method="post">
<p>Your T&C here</p>
<input type="checkbox" name="agree" value="agreed" />
<input type="submit" value="go" />
</form>
PHP: target.php
<?php
session_start();
if( !isset($_POST['agreed']) || $_POST['agreed'] != 'agreed' ){
header("Location: ".$_SESSION['prev_link']);
exit;
}
?>
Your target page content here
EDIT: Edited to show T&C page instead of directly redirecting.
EDIT 2: Now the intermediate page will redirect automatically upon agreeing/clicking the checkbox.
PHP: inter.php
<?php
session_start();
$link='#';
switch($_GET['target']) {
case 1:
$link = "http://nexttarget.com";
break;
case 2:
$link = "http://nexttarget2.com";
break;
case "something_else":
$link = "http://nexttarget3.com";
break;
}
$_SESSION['prev_link'] = "http://source_url";
?>
<form action="<?php echo $link; ?>" method="post" id="tc_form" >
<p>Your T&C here</p>
<input type="checkbox" name="agree" value="agreed" onclick="javascript: this.parentNode.submit();" id="check" />
<label for="check">I agree to the T&C.</label>
</form>
Upvotes: 1
Reputation: 9359
An approach that's used a lot goes like this:
intermediary-page.php?proceedTo=some/url/to-go-next.php
On the intermediary-page.html (or php or whatever) page you perform the necessary verifications and redirect the user to the url available in proceedTo
GET variable.
After that, it depends on your requirements. Do you want security or ensure that the user has accepted the terms and conditions or whatever? Then you should perform additional verifications on each page like so:
Link 1 -> Page 1 (check if the user has accepted the terms already? no? then:) -> intermediary?proceedTo=page1 -> (ask the user to accept! accepted? then:) -> Page 1 (user has accepted the terms now? yes? then:) -> stay here...
The advantages of this approach are:
href="intermediary.php?next=abc.php"
, instead just go with simple href="abc.php"
which will handle redirection itself.Upvotes: 0
Reputation: 3044
You can user GET variables in a URL. eg http://www.mysite.com/intermediary-page?page=page1
So this will link to the Intermediary page. Then on that page you will have a function that looks at the last part of the url page=page1.
Then that function will then redirect the user to the correct page.
Upvotes: 1
Reputation: 9417
your HTML link:
<a href="/links.php?page=1">Link 1</a>
<a href="/links.php?page=2">Link 1</a>
your PHP code in links.php
:
<?php
$page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : null;
if (!empty($page)) {
switch ($page) {
case 1:
header('Location: abc.php');
break;
case 2:
header('Location: xyz.php');
break;
}
}
The other options is:
$pages[1] = 'abc.php';
$pages[2] = 'xyz.php';
header('Location: ' . $pages[$page]);
Note: Try to secure the $page
variable, before using it.
Upvotes: 0
Reputation: 15106
First HTML page
<a href="intermediary.php?q=1">Link 1</a>
<a href="intermediary.php?q=2">Link 2</a>
<a href="intermediary.php?q=3">Link 3</a>
<a href="intermediary.php?q=4">Link 4</a>
<a href="intermediary.php?q=5">Link 5</a>
intermediary.php
<?php
$link = (int)$_GET["q"];
?>
<a href="page<?=$link?>.html">I agree to the terms and conditions</a>
Upvotes: 2
Reputation: 3998
First page:
<a href="intermediary.php?next_page=somepage.php">link to Intermediary Page</a>
Intermediary Page:
<?php
$next_page = $_REQUEST["next_page"];
header("Location: " . $next_page);
?>
Upvotes: 0