SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Help Newbie Question: PHP GET

    I have searched the forum up and down. I was unable to locate a similar solution. Forgive me for being a newbie.

    I have a website which has a bunch of affiliate products on it which I review.

    I want to send all of my outbound links to a redirect page. I do not want to have 200 redirects on my website, so I would like to build it in PHP.

    LINK EXAMPLE ON MY SITE: hxxp://www.mydomainname.com/redirect.php?site=dogtrainer

    On the next page which is REDIRECT.PHP I need to do the following. But that is my problem...I'm a NEWBIE

    redirect.php will need to GET the Variable from the URL.
    From this point on is where I am confused on the best way to do this.

    I am going to have maybe 100 + Affiliate URL's.
    Each affiliate URL will have an associated TITLE.

    So when I GET the variable from the URL I need to build the code below where the TITLE and URL are dynamic based on the GET Variable.

    I do not know the complexity of what I am asking...but any help with this will be much appreciated.

    Thanks in Advance for all of your help.



    PHP Code:
    <html>
    <
    head>
    <
    title>TITLE OF PAGE</title>
    </
    head>
    <
    frameset border="0" frameborder="0" marginleft="0" margintop="0" marginright="0" marginbottom="0" rows="100%,*">
    <
    frame src="URL FOR AFFILIATE WEBSITE" scrolling="auto" frameborder="no" border="0" noresize>
    <
    frame topmargin="0" marginwidth="0" scrolling="no" marginheight="0" frameborder="no" border="0" noresize>
    </
    frameset>
    </
    html

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    Newcastle, England
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <html>
    <head>
    <title><?php $_GET['title'] ?></title>
    </head>
    <frameset border="0" frameborder="0" marginleft="0" margintop="0" marginright="0" marginbottom="0" rows="100%,*">
    <frame src="<?php $_GET['url'] ?>" scrolling="auto" frameborder="no" border="0" noresize>
    <frame topmargin="0" marginwidth="0" scrolling="no" marginheight="0" frameborder="no" border="0" noresize>
    </frameset>
    </html>

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thejackel, thanks for your Quick response. Your suggestion will definately work...I am just not sure it is going to be suitable for this project...

    I take it you recommend that I pass both the title and the AFFILIATE URL via the query string? - It seems pretty messy to pass a full HTTP in the query string... Do you have any other ideas?

    • I need to pass a full URL which in some cases can be quite long.
    • I also need to pass a page title which can be pretty long as well.


    Do you think it would be to difficult to match up the VARIABLE from GET with an IF / ELSE or an ARRAY?

    What are you thoughts on this.

    This was the direction I was heading - please correct me if I am wrong.

    I just don't know if these are FAST enough If I have as many as 100 items in my IF ELSE or ARRAY?

    Please Advise.

  4. #4
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if I am beating a dead horse here...I am just trying my best to explain this...so I can get the right answer.

    So I am going to try again.

    So a user will click a link on my site (BELOW) and then he will go to a php page on my server which will look for the Variable "SITE".

    I need the variable site to match up with a TITLE (see below) and a FULL URL (see below). I want to do this without passing it (title and full url) through the query string because that is the whole point of this PAGE/FRAMESET is to hide my affiliate URL. I can live with passing a single variable through the URL such as in my example link below.

    Thanks again for your help in advance.

    LINK EXAMPLE ON MY SITE: http://www.mydomainname.com/redirect...ite=dogtrainer


    <?php
    $affiliate = $_GET['site'];
    ?>

    http://www.training-your-pitbull-mad...filiateid=1234
    http://www.someaffiliate2.html?affiliateid=1234
    http://www.someaffiliate3.html?affiliateid=1234
    http://www.someaffiliate4.html?affiliateid=1234
    http://www.someaffiliate5.html?affiliateid=1234
    http://www.someaffiliate6.html?affiliateid=1234
    http://www.someaffiliate7.html?affiliateid=1234
    http://www.someaffiliate8.html?affiliateid=1234
    http://www.someaffiliate9.html?affiliateid=1234


    Learn the Secrets of Training Pitbull Puppies
    This is an Example Title of Affiliate URL 2
    This is an Example Title of Affiliate URL 3
    This is an Example Title of Affiliate URL 4
    This is an Example Title of Affiliate URL 5
    This is an Example Title of Affiliate URL 6
    This is an Example Title of Affiliate URL 7
    This is an Example Title of Affiliate URL 8
    This is an Example Title of Affiliate URL 9

  5. #5
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pass a unique identifier as you have (it might be better to use a number) and store the affiliate information in a database. You re-direct page would access the database using the identifier and retrieve the URL and any other information needed in the redirection.

    You wouldn't have to use a database, but whatever you choose consider the security, reliability and practicality of thar system.

  6. #6
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, I was thinking the database was probably the best option...but an a newbie I really did not want to have to get that involved.

    --

    So back to the original question...this is more practical to me because it does not need to be secure system. I just prefer it like this for ease of use on my part.

    --

    Are Multi Deminsional Arrays better in this case or IF / ELSE statements better in terms of speed. Keep in mind I might have over 100 URL's and Page Titles.

  7. #7
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Believe it or not, that isn't that much data to process.

    If you store the information you need in a flat file, in a serialized PHP form, you could get the right into quickly by using the identifier as the key in an associative array. No need to use a lot of if constructs.

  8. #8
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so based on what you are saying...here is PSEUDO Code for what i am trying to do... please advise.

    PHP Code:

    if (isset($_GET['site']))
    {
       
    $title $_GET['site'];
       }
       else
       {
       
    $title NULL;





    $affiliate['weburl'][0]='http://www.training-your-pitbull-made-easy.html?affiliateid=1234';

    $affiliate['weburl'][1]='http://www.affiliate-url.html?affiliateid=1234';

    $affiliate['weburl'][2]='http://www.another-affiliate-url.html?affiliateid=1234';



    $affiliate['title'][0]='Learn the Secrets of Training Pitbull Puppies';

    $affiliate['title'][1]='Title of Affiliate URL Website';

    $affiliate['title'][2]='Another Title of Affiliate URL Website'

  9. #9
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could pass a NUMERIC variable in the Query String which would match up with the Array.

    http://www.mylink.com?site=2

    Now the idea is that the Variable "SITE=2" will return 2 results from the multi deminsional array above.

    URL - http://www.another-affiliate-url.html?affiliateid=1234
    TITLE - Another Title of Affiliate URL Website

    these two values could then be assigned dynamically into the FRAME code above in the first post.

    It this starting to sound right? Problem is ... I am still such a newbie I have no clue how to execute on it.

  10. #10
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    http://www.yourdomain.com/redirect.php?af=splunge
    PHP Code:
    if(empty($_GET['af']) || !isset($aflinks[$_GET['af']]))
    {
       
    header('Location: oops.php');
       exit();
    }
    else
    {
       
    $aflinks['splunge']['url'] = 'http://www.montypython.com/splunge.php';
       
    header('Location: '.$aflinks[$_GET['af']]['url']);
       exit();


  11. #11
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hammer65 - thanks for the help I really appreciate it.

    I tested the code above and it went to OOPS.php each time.

    Is that what it is supposed to do? Forgive my NEWBIE'ness

  12. #12
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the $_GET variable "af" is there and the value matches one of the keys, it should work.

  13. #13
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have copied the code above and put in on my server "index.php"

    I have a link on my page going here: http://www.hoosiermate.com/?af=splunge

    THE PHP is in my index.php in the root of www.hoosiermate.com

  14. #14
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Am I missing something here?

  15. #15
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been searching this forum this entire time...

    I found something...it looks similar...is this of any help to you...to help me...

    TIA

    http://www.sitepoint.com/forums/showthread.php?t=488147

  16. #16
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    Newcastle, England
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Looking back at post 8 it seems you are close to cracking it yourself. Ive slightly modified your code and heres what I have

    Code PHP:
    // Include your array in a separate file say 'links.php' (more easily manageable)
    // use require_once('links.php'); to load it (ensure its at the top of page)
     
    $affiliate['weburl'][0]='http://www.training-your-pitbull-made-easy.html?affiliateid=1234';
    $affiliate['weburl'][1]='http://www.affiliate-url.html?affiliateid=1234';
    $affiliate['weburl'][2]='http://www.another-affiliate-url.html?affiliateid=1234';
    $affiliate['title'][0]='Learn the Secrets of Training Pitbull Puppies';
    $affiliate['title'][1]='Title of Affiliate URL Website';
    $affiliate['title'][2]='Another Title of Affiliate URL Website'; 
     
    // Include this in you redirect page. Checks if the site variabl is set and also if it has a value
    if (isset($_GET['site']) && $_GET['site']!='')
    {
       $url = $affiliate['weburl'][$_GET['site']]; // store url
       $title = $affiliate['title'][$_GET['site']]; // store title
       // echo 'url -'.$url; // debug
       // echo 'title -'.$title; // debug
       }
       else
       {
       $title = NULL;
    }

    This way you can 1 number that relates to an individual link.

    Hope this is close to what you are after.


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
  •