Portal Home > Knowledgebase > Articles Database > PHP include and CGI


PHP include and CGI




Posted by tetrahedonism, 01-12-2010, 04:22 PM
Hello all! Thanks in advance for any help, but I've got a simple problem I can't really figure out or find help with. I'm trying to set up a webpage with CGI:IRC embedded inside of it. Nothing to hard, but everytime I try and excute anything beyond the Nickname/server/channel page, it 404's and tries to redirect. I don't know all that much about php or cgi, but all I need is for the script to excute on the same page. The code is as follows

Posted by mattle, 01-12-2010, 05:45 PM
Sounds like there are links in the CGI script that are trying to take you to pages that don't exist (maybe using relative linking?). The only way I really see of doing this would be not recommended. I'll outline it anyway, in case anyone has better ideas: Let's assume your php script is irc.php, you would need to do a rewrite to your PHP files from all the invalid links to CGI pages: RewriteRule ^(.*\.cgi)$ irc.php?page=/$1 (see a recent thread in this forum for more mod_rewrite info...the OP is doing almost exactly the same thing) Then, and this is the ugly part, you would need to dynamically load the CGI script

Posted by tetrahedonism, 01-12-2010, 05:49 PM
Thanks for the reply, I just ended up doing the code below. It works pretty flawlessly, thankfully!

Posted by mattle, 01-12-2010, 05:52 PM
Yeah...I'd stick with that...that's way safer than passing a variable to virtual()

Posted by foobic, 01-12-2010, 05:55 PM
Can you reverse the logic? ie. call the cgi script directly and add your standard page HTML to its template (if it has one) or just wrapped around the regular script output.

Posted by tetrahedonism, 01-12-2010, 09:28 PM
Can you give me an example? I'm still learning.

Posted by foobic, 01-12-2010, 10:17 PM
Hmm, yes, it wasn't the clearest comment... I'll try to explain better what I meant. You're trying to set up a web page using PHP that has a cgi script embedded in it. But the cgi script itself is perfectly capable of generating a complete web page (it must be, or the iframe trick wouldn't work). So somewhere in the cgi script there are instructions for generating a web page. Exactly how it does this depends on the script but often you'll find it uses some form of template, perhaps in the script itself, perhaps read from an outside file. It might then add the dynamic content to the rest of the page at a point specified by some sort of marker. Supposing your cgi script reads its template from an outside file, and the marker is "[CONTENT]" you could change that file to this: or whatever more complex HTML you might want to use, including your site's standard menu, header, footer etc. There are no rules dictating how a cgi script must be written so yours could be quite different to the above, but it must have the same basic functionality - you just need to find out what it's doing and customise it yourself. If you can set the script up to produce the entire page the way you want it, there's no need to embed it in another page.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
phpLibClamAV (Views: 578)
cliff support (Views: 624)