1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Perl -> PHP Coop Wrapper

Discussion in 'Co-op Advertising Network' started by clickdoc, Jan 18, 2005.

  1. #1
    I had a hard time finding the other perl -> php wrapper thread so I though I would start a new thread with these step by step instructions to make it easier for people who need this in the future. I will update this thread if changes are ever needed. I don't forsee any however since this just wraps Shawn's code. All you will need to update is ad_network.php and possibly coop.php if Shawn adds more tracking features in the future.

    I've gotten a couple PM's from people having trouble so I am including a step by step setup for the wrapper. Both for people who need to include the wrapper code in an existing perl script and for those who are doing it using an SSI include.

    Here are the steps I use to set it up.

    First I make a directory /php/ on my server where php is enabled.

    Then I copy Shawn's ad_network.php into that directory and create ad_network_ads.txt and make it writable by the web process.

    Next I create coop.php in that directory with the following contents:

    <?php
    $_SERVER['REMOTE_ADDR'] = $_REQUEST['ip'];
    include ('ad_network.php');
    echo $ad_network[0] . ' | ' . $ad_network[1] . ' | ' . $ad_network[2] . ' | ' . $ad_network[3] . ' | ' . $ad_network[4];
    ?>

    This is to show 5 ads with a | separating them. To only show one add delete everything after $ad_network[0] up to but not including the semi colon.

    If you are displaying 5 ads then as Shawn pointed out a cleaner way to do the above is to replace that whole echo line with this one:

    echo implode (' | ', $ad_network);


    Then test this page by going to it in your web browser http://www.yourserver.com/php/coop.php

    You should see a coop ad. If you see an ad here then all that is left to do is to add the perl wrapper portion.

    If you have a perl script and need to put the coop inside it without calling an outside routine here is the code you can put right inside a script. Be sure to set the full http path in the ad_url variable to where you ran coop.php in the web browser successfully.


    ## START perl->php wrapper code

    use LWP::UserAgent;

    # set the full http path to the ad page here:
    my $ad_url = qq{http://www.yourserver.com/php/coop.php};

    $ad_url .= qq{?ip=} . $ENV{REMOTE_ADDR};

    my $output = '';

    my $ua = new LWP::UserAgent;
    $ua->agent("Perl-Php-Coop-Wrapper/1.2");
    my $req = HTTP::Request->new(GET => $ad_url);
    my $res = $ua->request($req);
    if($res->is_success) {
    $output .= $res->content;
    }

    print $output;

    ## END perl->php wrapper code





    If you need to use it as a SSI and for some reason don't want to use php here is the code to put in your SSI included script. Be sure to set the full http path in the ad_url variable to where you ran coop.php in the web browser successfully.

    Note that number of ads and separator values are now set in the coop.php and not with parameters passed to the include as with the old perl version.



    #!/usr/bin/perl

    # $Id: coop_wrapper.cgi,v 1.2 2005/01/07 21:19:02 cvs Exp $
    # $Revision: 1.2 $

    use strict;
    use LWP::UserAgent;

    # set the full http path to the page here:
    my $ad_url = qq{http://www.yourserver.com/php/coop.php};

    $ad_url .= qq{?ip=} . $ENV{REMOTE_ADDR};

    my $output = '';

    $output .= qq{Content-type: text/html\n\n} if($ENV{GATEWAY_INTERFACE} =~ /CGI/);

    my $ua = new LWP::UserAgent;
    $ua->agent("Perl-Php-Coop-Wrapper/1.2");
    my $req = HTTP::Request->new(GET => $ad_url);
    my $res = $ua->request($req);
    if($res->is_success) {
    $output .= $res->content;
    }

    # uncomment this line if you are seeing Content-type: text/html in your page
    # $output =~ s/Content-type: text\/html//;

    print $output;
     
    clickdoc, Jan 18, 2005 IP
    nevetS likes this.
  2. seoxperts

    seoxperts Peon

    Messages:
    453
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    VERY Thanks for this.
     
    seoxperts, Jan 18, 2005 IP
  3. freedom2

    freedom2 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Clickdoc (or anyone!)

    Can you tell me if I am using the ssi method what I am supposed to put in the html pages themselves? Is it:

    [!--#include virtual="/cgi-bin/coop_wrapper.cgi?"-->]

    2) Is the method above it of this: ## START perl->php wrapper code
    to create php pages vs html pages?
    I need it to be html pages because my pages on site already are made and already call cgi scripts using ssi tags.

    3) For the ssi method , can I use additional domains that call this from my first domain:
    # set the full http path to the page here:
    my $ad_url = qq{http://www.yourserver.com/php/coop.php};

    4) Also to make the ad_networks txt writable is that 777 or 766 or 666?


    Thanks!
     
    freedom2, Jan 23, 2005 IP
  4. clickdoc

    clickdoc Guest

    Messages:
    39
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    freedom2:

    This is the code to put in coop_wrapper.cgi:

    #!/usr/bin/perl

    # $Id: coop_wrapper.cgi,v 1.2 2005/01/07 21:19:02 cvs Exp $
    # $Revision: 1.2 $

    use strict;
    use LWP::UserAgent;

    # set the full http path to the page here:
    my $ad_url = qq{http://www.yourserver.com/php/coop.php};

    $ad_url .= qq{?ip=} . $ENV{REMOTE_ADDR};

    my $output = '';

    $output .= qq{Content-type: text/html\n\n} if($ENV{GATEWAY_INTERFACE} =~ /CGI/);

    my $ua = new LWP::UserAgent;
    $ua->agent("Perl-Php-Coop-Wrapper/1.2");
    my $req = HTTP::Request->new(GET => $ad_url);
    my $res = $ua->request($req);
    if($res->is_success) {
    $output .= $res->content;
    }

    # uncomment this line if you are seeing Content-type: text/html in your page
    # $output =~ s/Content-type: text\/html//;

    print $output;


    Make sure you test it at each step along the way.

    1. Setup a directory that supports php and put ad_network.php, ad_network_ads.txt, and coop.php in it. Make ad_network_ads.txt writable by the web process, or just chmod 666 if you don't know who the web process is.

    2. Test coop.php in your web browser.

    3. Copy above code into coop_wrapper.cgi, edit $ad_url to put in the full http: url of your coop.php file that you just tested in the browser.

    4. Test coop_wrapper.cgi in the browser, coop_wrapper.cgi must reside on the same host as your website, where coop.php does not have this requirement.

    5. Inlude coop_wrapper.cgi with the virtual command:

    <!--#include virtual="/cgi-bin/coop_wrapper.cgi?" -->

    If you have tested each along the way and they worked then the include should work as well. Good Luck.
     
    clickdoc, Jan 24, 2005 IP
  5. freedom2

    freedom2 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi and thank you for the help. I will try it right now (I've been up for like 8 hours trying it). Interestingly enough I actually got things to work following a different set of instructions someone posted elsewhere on forum and I saw the ads on every page too but it wouldn't validate and Shawn said Your site doesn't seem to be evaluating/seeing the $_SERVER['REMOTE_ADDR'] properly.

    Anyway, I will start from scratch with your method and may post again! If you do installs or can recommend someone , please email or pm me. I am losing a lot of hair!
     
    freedom2, Jan 24, 2005 IP
  6. freedom2

    freedom2 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    OOPS I forgot to ask you this:

    Does the coop_wrapper.cgi need to be set to 755? Thank...
     
    freedom2, Jan 24, 2005 IP
  7. freedom2

    freedom2 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    IT worked!! You are a genius!! Thank you sooo much.. For me it didn't work initially when I tried to link directly to the coop.php file.. what worked was the wrapper method clickdoc talked about.
     
    freedom2, Jan 24, 2005 IP
  8. Spyware Remover

    Spyware Remover Peon

    Messages:
    126
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The only thing I can get to dispaly is the content of coop_wrapper.cgi

    FYI, I am trying to get the co-op ads to display on the Amazon Products Feed script pages.

    If anyone is familiar with that, your help is GREATLY appreciated!

    I have been putting the include for the APF pages on the "template" page.

    If the include needs to go on the cgi pages, where would it go?

    AJ
     
    Spyware Remover, Jan 25, 2005 IP
  9. a389951l

    a389951l Must Create More Content

    Messages:
    1,885
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    140
    #9
    What version of AWS are you using? If you are using the latest, there is a mod you can use to include it within templates. I am using AWS 3 and you will need to incorporate it within your aws perl script itself and includes will not work within the script.
     
    a389951l, Jan 25, 2005 IP
  10. Spyware Remover

    Spyware Remover Peon

    Messages:
    126
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I am using AWS4, the version that just came out this past weekend.

    What mod do I need to use and where may I find it?

    Thanks!

    Andrew
     
    Spyware Remover, Jan 25, 2005 IP
  11. a389951l

    a389951l Must Create More Content

    Messages:
    1,885
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    140
  12. Spyware Remover

    Spyware Remover Peon

    Messages:
    126
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Great,thanks!

    Now, as a newbie, how do I implement the MOD?

    AJ
     
    Spyware Remover, Jan 25, 2005 IP
  13. mream

    mream Guest

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I could use a little help here:

    My coop.php works fine, but I'm getting "500 Internal Server Error" on the coop_wrapper.cgi.

    I'm not sure what I'm doing wrong.

    Thanks,
     
    mream, Jan 27, 2005 IP
  14. chachi

    chachi The other Jason

    Messages:
    1,600
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Matt, do you need to use the cgi version?
     
    chachi, Jan 27, 2005 IP
  15. mream

    mream Guest

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I used the cgi version that was posted here, and I have the correct path for my coop.php.

    I'm not a cgi expert, so I'm not sure what else I can look at.

    Any suggestions?
     
    mream, Jan 27, 2005 IP
  16. chachi

    chachi The other Jason

    Messages:
    1,600
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Yes, my suggestion is to use the PHP version supported by DP if you can. That is why I asked if you "need" to use the .cgi version.
     
    chachi, Jan 27, 2005 IP
  17. mream

    mream Guest

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Ok, I guess I misunderstood. I'm trying the cgi version, because I couldn't get the php version to work.

    What I've got is a directory, with mostly html pages, which all work fine. I have the code in a footer that calls ad_network.php and everything is great.

    I have some cgi pages that call html pages (add_url type pages) that I just can't get any code to work on. I've tried putting code in the html and cgi pages, and nothing works. I can see the "|"s I have between ads, but no ads are showing.
     
    mream, Jan 27, 2005 IP
  18. mream

    mream Guest

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Here's what appears in my error log... if anyone can help me solve this I will be very glad.

    [27-Jan-2005 23:04:15] PHP Warning: file_get_contents(): URL file-access is disabled in the server configuration in /home/steps10/public_html/ad_network.php on line 37
    [27-Jan-2005 23:04:15] PHP Warning: file_get_contents(http://ads.digitalpoint.com/network.php?b=www.10000-steps.com&type=link): failed to open stream: no suitable wrapper could be found in /home/steps10/public_html/ad_network.php on line 37
     
    mream, Jan 27, 2005 IP
  19. clickdoc

    clickdoc Guest

    Messages:
    39
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #19
    you say that coop.php works fine? you mean you see ads with coop.php? this error in your logs is a php error which to me means that your ISP doesn't allow you to get remote files with the file_get_contents(). however my php is limited. maybe shawn can answer that question.

    for your 500 error on the wrapper please post the error in the logs. have you set the coop_wrapper.cgi to mode 755? i guess i should put that in the setup steps.
     
    clickdoc, Jan 28, 2005 IP
  20. mream

    mream Guest

    Messages:
    96
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Thanks for your help. I'm getting closer. I can now see the ads in coop_wrapper.cgi. I had some weirdo version of that file, so I updated it and changed it to 755. That was important.

    Now, hopefully my final question on this topic. The virtual include command... should that go in my cgi script that calls the html, or my html file? I can't seem to see anything when I put it in either place.

    Thanks,
     
    mream, Jan 28, 2005 IP