Dynamically Generating Curl Content'

VERSION 11 Published

Created on:Oct 16, 2007 11:53 AM by admin - Last Modified:  Oct 24, 2007 7:55 AM by CurlEducation

Dynamically Generate Curl Content

With server-side technologies such as ASP and PHP, you can use Curl applets to generate content on the fly. Dynamic data can be placed into a .curl file on the server before the file is sent to the user's browser.

Curl works with server languages such as ASP, JSP, PHP, and CGI in two ways:

  1. A Curl applet can be directly launched from the executing script
  2. Curl language content can be embedded directly in the server script.
In either case, once the Curl is launched, the Curl content is sent from the server to the client machine and all processing of Curl happens on the client machine.

In this Curl Cue, we will present examples using ASP and PHP. If you are familiar with either scripting languages, you will notice that what would otherwise be HTML has been replaced with Curl code.

Execute Curl from a Script

In the following examples, we are using ASP or PHP to dynamically generate Curl content. If you are familiar with scripting languages, you will notice that what would otherwise be HTML has been replaced with Curl code.

In either case, you will have to:

  1. Identify the server scripting language, for example: ?php
  2. State the MIME type declaration for Curl content, for example: text/vnd.curl
  3. Embed well-written Curl applet code

The following examples both generate similar Curl code:

http://uat.communityxperts.net/wiki/samples/images/phpscript.jpg

PHP Example


<?php
/**
 *
 * PHP example
 *
 */
header('Content-type: text/vnd.curl');
// All of the above code is PHP.
// What follows the next line (i.e., after "echo <<<END") is Curl code.
echo <<<END

{curl 5.0 applet}

{value
    {Frame
        width = 5cm,
        height = 5cm,
        border-color = "gray",
        border-width = 0.1cm,
        border-style = "raised",
        background = "#4578ef",
        {hcenter
            {vcenter
                "A PHP script on the server generated this applet."
            }
        }
    }
}

END;
// The Curl code ended before the previous line (i.e., before "END;").
?>

ASP Example



<A HREF="dynamic-applet.asp?"> Generate Curl content from an asp file</A>

<%@ LANGUAGE=vbscript%>
<% Response.ContentType = "text/vnd.curl" %>

{curl 5.0 applet}

{value
    {Frame
        width = 5cm,
        height = 5cm,
        border-color = "gray",
        border-width = 0.1cm,
        border-style = "raised",
        background = "#4578ef",
        {hcenter
            {vcenter
                "An ASP script on the server generated this applet."
            }
        }
    }
}

Passing Variables from a script

The previous examples demonstrate how to generate Curl content directly from a server script. Now we are adding in the use of variables. It is common that you may have script variables that store relevant information about the session such as:

  • Session ID
  • Cookie information
  • Username
  • Other user identification information

The following is an example of Curl being generated by a PHP script. It includes the use of a variable ($variable) which is set by calling a function in a separate PHP file to obtain a username for display in the Curl applet.

The resulting content displayed is:

http://uat.communityxperts.net/wiki/samples/images/phpvariable.jpg

PHP Example


<?php
 
// Include any supporting PHP code.
include("supporting-php-code.php");
 
// Set the Curl MIME type
header('Content-type: text/vnd.curl');
 
// Set a variable using your PHP code.
$variable = getUsername();
 
// All of the above code is PHP.
// What follows the next line (i.e., after "echo <<<END") is Curl code.
echo <<<END

{curl 5.0 applet}
 
{value
    {Frame
        width = 5cm,
        height = 5cm,
        border-color = "gray",
        border-width = 0.1cm,
        border-style = "raised",
        background = "#4578ef",
        {hcenter
            {vcenter
                "Hello " &#38; "$variable" &#38; "!"
            }
        }
    }
}
 
END;
// The Curl code ended before the previous line (i.e., before "END;").
?>

Notice on the code displayed above that we are including supporting PHP code. In this case, the file supporting-php-code.php contains the following content:



} 
<?php

function getUsername() {
  return "Curl User";
}
?>

ASP Example



<%@ LANGUAGE=vbscript%>
<% Response.ContentType = "text/vnd.curl" %>

<% variable= getUsername() %>

{curl 5.0 applet}
 
{value
    {Frame
        width = 5cm,
        height = 5cm,
        border-color = "gray",
        border-width = 0.1cm,
        border-style = "raised",
        background = "#4578ef",
        {hcenter
            {vcenter
                "Hello " &#38; "<% =variable%>" &#38; "!"
            }
        }
    }
}

End of Curl content.

http://uat.communityxperts.net/wiki/samples/images/note.jpg Other ways to run Curl applets...

Average User Rating
(0 ratings)




There are no comments on this document