Post Reply 
 
Thread Rating:
  • 348 Votes - 2.8 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serving Content3:Dynamically Generating Curl Content
06-15-2011, 05:19 PM (This post was last modified: 06-24-2011 10:15 AM by kino.)
Post: #1
Serving Content3:Dynamically Generating Curl Content
With server-side technologies such as ASP and PHP, you can use Curl applets that are generated on the fly. Dynamic data can be placed into a Curl applet that is sent from a server to the user's browser.


Curl works with server languages such as ASP, JSP, PHP, and CGI. Scripts in these languages can generate Curl applets to be launched on the client machine, after which all Curl processing happens on the client machine.


Generating 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 correctly formed Curl applet code


The following examples both generate similar Curl code. They produce a display like this when run.


PHP Example
Code:
/**
*
* PHP example
*
*/
header('Content-type: text/vnd.curl');
// All of the above code is PHP.
// What follows the next line (i.e., after "echo <{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
Code:
{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:

PHP Example
Code:
// 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 <{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 " & "$variable" & "!"
}
}
}
}

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:

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

In an actual application, the getUsername function retrieves information from one of the data sources mentioned above.


ASP Example
Code:
{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 " & "" & "!"
}
}
}
}


Other ways to run Curl applets include the following:

•Launching a Curl applet from another Curl applet. Please see Launching a Curl Applet.

•Embedding Curl in HTML. Please see Launching and Embedding Curl in HTML.


Attached File(s)
.jpg  phpscript.jpg (Size: 7.48 KB / Downloads: 696)
.jpg  phpvariable.jpg (Size: 4.96 KB / Downloads: 683)
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Styling1:Curl Styles kino 0 4,521 06-16-2011 09:14 AM
Last Post: kino
  Serving Content2:Launching and Embedding Curl in HTML kino 0 8,086 06-15-2011 05:15 PM
Last Post: kino
  Serving Content1:Launching a Curl Applet kino 0 4,451 06-15-2011 05:12 PM
Last Post: kino
  User Interface Basics5:Swapping UI Content kino 0 2,943 06-15-2011 04:03 PM
Last Post: kino
  User Interface Basics1:Linking to Content kino 0 3,204 06-15-2011 03:48 PM
Last Post: kino
Forum Jump:


User(s) browsing this thread:
1 Guest(s)