Support » Fixing WordPress » How do I integrate a Perl CGI script with WordPress

  • Hi,

    I have a client that needs a Perl CGI script integrated with his site. It is meant for his affiliate company to know when a purchase is made off of his site.

    Thanks in advance for any help you can lend.

Viewing 3 replies - 1 through 3 (of 3 total)
  • To my knowledge, there is only one reliable way to include a Perl cgi within a PHP (such as WordPress) file. In what follows, I assume that your web host supports what is necessary, and that you already have adequate knowledge. In other words, this is not for beginners.

    Usually, writing a Perl cgi include statement into the original PHP file does not work. It MIGHT work on some hosts. But in general, the result of the PHP processing is sent out without being re-parsed for Perl, no matter how you configure your.htaccess files.

    What you can do: In your PHP, put an inline html element (if using transitional doctype, the norm for WordPress). If using strict doctype, use an object element. You will probably wish to play with the css for the including page, as was as with the css for the included page, so that the browser does not show scrollbars or a window border. How to do this cross-browser can be searched on the Internet.

    Have your inline (or object) element call another html page (not PHP). This included page will have your Perl cgi include statement.

    When your including page (the one that the visitor actually sees) loads in the visitor’s browser, it will then fetch the included html page (the one with the cgi) and activate its cgi in the normal fashion.

    Some environment valiables, such as the visitor’s user agent and web host, will be the same for the including and included pages. But the critical variable, namely the referrer (referer), will be different. The cgi will think that it was referred by your own including page!

    To fix this problem, have your including page detect environmental variables such as the visitor’s referring page and search terms, then pass these as a query string in the inline (or object) code. You may do the detection in server-side PHP or client-side JavaScript, if you wish. You probably will need to escape the strings.

    I recommend using client-side JavaScript, rather than server-side PHP, to detect the necessary environmental variables and pass these as the query string. You can write the whole inline (or object) element with JavaScript. Be sure to reserve the needed amount of page space by placing the element in a div of known size, so that the page does not reflow when the script is activated.

    If your cgi script does not read what you need from the query string, then you will have to modify its code.

    If you are a purist, you might wish to place the included html page (the one with the cgi) in a directory that cannot be read unless the html page is called from within another one of your pages. Alternatively, you can re-write the cgi so that it does not do its thing unless it detects that it has been called from within your site.

    Be sure that the included html file has meta robots noindex nofollow.

    I cannot guarantee that this will do what you want it to do for all kinds of cgi. But I have used it in the past for another purpose, and it did work.

    I didn’t post code here, since it is custom code, and anyone who couldn’t figure it out would probably cause other problems.

    Afterthought: You web host MIGHT have some pre-written code that can be used as a “wrapper” for the specific purpose of putting cgi ads into PHP pages. To find out, log in to your host, and poke around to see if there are any existing modules that you can activiate or insert into a page. I have never tried this, but I notice that my host has some kind of function that allows (name of ad service) banners to be placed on pages that otherwise wouldn’t support them. No idea if it works.

    In my above post, I started out by assuming that “known techniques” did not work for you, probably because your server is incompatible (or is configured to disallow what you need).

    Later, I realized that the “known techniques” are obscure. Have a look at this other forum, which might get you started:

    execute perl cgi from php

    On my old host, I had no trouble putting Perl CGI into PHP, because my resources were already configured that way. On my new host, I can still do it, but I have to play with the server configuration myself. Both used Apache.

    The method I suggested in my earlier post might work for you if you are not on Apache, or if you cannot configure what you need.


    I tried to do the same thing and got this page as first search result. This is how I solved it. I created a new page, clicked the HTML tab and inserted the following html-code in it:

    <iframe src="/cgi-bin/" name="ircframe" width="100%" marginwidth="0" height="600" marginheight="0" scrolling="auto">
    Your browser does not support the iframe tag.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I integrate a Perl CGI script with WordPress’ is closed to new replies.