htmlperlperl-moduleperlscript

How to call a perl script in html


How to call a perl script which is returning data "text" type inside a html file.Posting the perl script for reference.This script has to be called in the index.html so how to do that

#!/usr/bin/perl -w  

use CGI;  

my $cgi = CGI->new;  
my $remote = $cgi->remote_host();  

my $AB = "16.108";  
my $CD = "16.214";  
my $EF = "10.99";  
my $GH = "10.243";  
my $XY = "10.179";  

my @remote_ip_values = split(/\./, $remote);  

my $remote_ip = $remote_ip_values[0] .".". $remote_ip_values[1];  

print "Content-type: text/html\n\n";  
print "document.write(\"<style>\\n\");\n";  
print "document.write(\"font color:red;\\n\");\n";  


if ($remote_ip eq $AB)  
{  
print "document.write(\"SUCCESSFUL\");\n";  

}  
 else  
{  
print "document.write(\"TEST\");\n";  
}  
exit;  

Solution

  • I am editing my answer as I now understand what you are trying to do. I have set up a simple example which will load the content from "another website" - which for you will be your Perl CGI.

    This HTML uses some simple JQuery. I am loading the following HTML page, http://chocksaway.com/tester.html and copying the contents into the "test" div:

    <!DOCTYPE HTML>
    <html>
        <head>
            <title>Loader</title>
        </head>
        <body>
            <div id="test"></div>
                <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
                <script type="text/javascript">
                    $(document).ready(function() {
                        $('#test').load('http://chocksaway.com/tester.html');
                    });
                </script>
        </body>
    </html>
    

    http://chocksaway.com/tester.html has the following HTML:

    <html>
        <header></header>
        <body> 
            this is a test so there
        </body>
    </html>
    

    If you open you http://chocksaway.com/tester2.html, you will see:

    this is a test so there
    

    Replace "http://chocksaway.com/tester2.html" with the URL of your Perl CGI.