View Full Version : Dynamic linking
magnusdahlquist
04-20-2009, 09:12 PM
Hey!
Do you know of any way that I can create dynamic links on one of my web pages?
For example: if I go to www.example.com/thankyou.php?link=link1, then link1 will link to one file, meanwhile if I go to www.example.com/thankyou?link=link2 then link2 will link to another file?
Thanks a lot guys,
Magnus
Schmoopy
04-20-2009, 10:55 PM
Depends, do you want the link to stay as it is? Or do you want the content to be different depending on the address?
If you want it to redirect, you can use something like this:
<?php
if(isset($_GET['link'])) {
if($_GET['link'] == 'about')
header('Location: http://www.yoursite.com/about.html');
elseif($_GET['link'] == 'home')
header('Location: http://www.yoursite.com/home.html');
}
?>
Or if you don't mean like that, then maybe:
<?php
if(isset($_GET['link'])) {
if($_GET['link'] == 'about') {
echo 'You are on the about page';
// Rest of content for about page here
}
elseif($_GET['link'] == 'home') {
echo 'You are on the home page';
// Rest of content for home page here
}
else {
echo 'Couldn't find the page you were looking for';
// Rest of content for when a page can't be found
}
}
?>
Hope that's what you're looking for, if not then please try and elaborate and I'll see if I can figure something out. Good luck :)
Edit: Sorry about bad formatting but can't tab out things when I type code here.
magnusdahlquist
04-22-2009, 10:17 PM
Hi!
Thanks for your response :)
I'm actually looking to create a dynamic download link for a PDF ebook.
I'm using the following code for my dynamic text on the site:
<?php
if ($_GET['kw'])
{echo $_GET['kw'];}
else
{echo "quality tattoo";}
?>
I would like to use something similar to generate the link (ie. based on whats the kw).
I have several different ebooks depending on what the client is interested about....Hmm...I hope you get what I mean?
:)
Schmoopy
04-23-2009, 12:36 AM
Well you'd pretty much do the same as before, I don't know what the conditions are though, like what the "kw" $_GET variable is.
But this maybe what you mean:
<?php
if(isset($_GET['kw'])) {
if($_GET['link'] == 'about')
header('Location: http://www.yoursite.com/' . $_GET['kw'] . '.pdf');
}
?>
So if the kw ivariable is set then it will redirect to the link
Otherwise the page won't be redirected. Is this what you mean?
borris83
04-23-2009, 07:48 AM
I think you are looking for this... This won't redirect the page using header() function but echo a html link dynamically depending on what is after www.example.com/thankyou.php?link=
You can modify this php block and paste in where you want the html link to be placed:
<?php
if(isset($_GET['link']))
{
$filename = $_GET['link'];
echo "<a href = \"http://www.example.com/files/" .$filename. "\">Download " . $filename . "</a>" ;
}
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.