Results 1 to 5 of 5

Thread: Dynamic linking

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic linking

    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

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    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 Code:
    <?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 Code:
    <?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.

  3. #3
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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 Code:
    <?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?

    Last edited by Snookerman; 04-22-2009 at 10:35 PM. Reason: added [php] tags

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    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 Code:
    <?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?

  5. #5
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    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:


    Code:
    <?php
    
    
    if(isset($_GET['link']))
    {
     
     $filename = $_GET['link'];
     
     echo "<a href = \"http://www.example.com/files/" .$filename.  "\">Download " .  $filename . "</a>" ;   
        
    }
    
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •