NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: Nick on May 22, 2014, 01:09:56 PM
-
Hi,
Can someone tell me at which point of the code the php-page will be send by the NT-webserver (with OddJob)
to the php-exe and at which point of the code the html-result will be returned to NT-webserver and then send
to the browser? Is that done in the Netwebhandler?
I've looked at the php-example but it is not obvious to me where this happens.
What makes a NT webserver "PHP aware", how does it know to serve php-pages?
Is it triggered just by the extension ".php"?
Thanks.
Nick
NT 7.34 C9.1
-
Hi Nick,
It's triggered by the php code inside the *.php page. I have done a tiny bit with php and Nettalk and it works quite well.
Here's an example of a *.php file updating an MS SQL database using php and Nettalk (the *.php file is placed in the 'web' folder:
<!-- NetWebServer -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>kwiklook Online - Induction Result Processing</title>
</head>
<body>
<?php
function get_only_numbers($string){
return preg_replace("/\D+/", "", $string);
}
$spOldType = $_GET["type"];
$spOldID = $_GET["id"];
$spMidType = get_only_numbers($spOldType);
$spMidID=(int)$spOldID;
if($spMidType=="12")
{
$spType="SP";
$spID=($spMidID/17);
}
if($spMidType=="9071")
{
$spType="SPS";
$spID=($spMidID/22);
}
$myServer = "MYSQLSERVERNAME";
$myUser = "USERNAME";
$myPass = "PASSWORD";
$myDB = "DATABASENAME";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer. Please press back and try again.");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB. Please press back and try again.");
//get today's date in Clarion format
date_default_timezone_set('Australia/Adelaide');
$unixTime = time();
$clarionDate = $unixTime / 86400 + 61730;
//declare the SQL statement that will query the database
$query = "SELECT OPT_InductionCredentialProfileID AS credProfileID FROM Options";
//execute the SQL query
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
//display the results
while($row = mssql_fetch_array($result))
{
$credProID = $row["credProfileID"];
}
$credProID = trim($credProID," ");
//declare the SQL statement that will query the database
$query = "UPDATE Credential ";
$query .= "SET CRE_Status = 'Pending', CRE_AttainmentDate = " . $clarionDate . " ";
$query .= "WHERE CRE_OwnerType = '" . $spType . "' AND CRE_OwnerID = " . $spID . " AND CRE_CredentialID = " . $credProID;
echo $query."\n";
//execute the SQL query
mssql_query($query);
////get name of Contractor
if ($spType=="SP")
{
$query = "SELECT PRO_GivenNames AS givenName, PRO_FamilyName AS familyName FROM ServiceProvider WHERE PRO_ProviderID = " . $spID;
}
else
{
$query = "SELECT VIS_FirstName AS givenName, VIS_LastName AS familyName FROM Visitor WHERE VIS_VisitorID = " . $spID;
}
//execute the SQL query
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
//display the results
while($row = mssql_fetch_array($result))
{
$spGivenName = $row["givenName"];
$spFamilyName = $row["familyName"];
}
$spName = trim($spGivenName," ") ." ". trim($spFamilyName," ");
$spName = rawurlencode($spName);
//close the connection
mssql_close($dbhandle);
?>
<script language="JavaScript" type="text/javascript">
var myName = "<?php print($spName); ?>";
window.location = 'InductionComplete.html?myName=' + myName;
</script>
</body>
</html>
Regards,
Trent
-
Hi Trent,
Thanks. I've got the PHP-example working too.
I still want to know:
at which point of the code the php-page will be send by the NT-webserver (with OddJob)
to the php-exe and at which point of the code the html-result will be returned to NT-webserver and then send
to the browser? Is that done in the Netwebhandler?
I would like to merge some stuff into the php-page each time before it is sent to php-exe so I need to know
at which point in code it goes to the php-exe.
I believe you can do this with NT but AFTER it is processed by php-exe.
Regards,
Nick
-
Hi Nick,
The php page gets processed by php-cgi.exe as soon as it is called. Whatever you put in the php code is what will be sent to the browser when the page is finished processing. In the example below you can see that I've added some Javascript to load an html page when completed. You could add in a Nettalk tag for a page/form/browse/source that will load when completed.
You can even include session varaibles. Just make sure you add the '<!-- NetWebServer -->' tag at the beginning of the page.
I'm not sure exactly where in the WebHandler this is processed, Bruce can answer this.
What exactly do you want to merge into the page each time it is called?
Regards,
Trent
-
>>The php page gets processed by php-cgi.exe as soon as it is called.
I think NT picks it up first and feeds it with OddJob to php-exe.
>>You can even include session varaibles. Just make sure you add the '<!-- NetWebServer -->' tag at the beginning of the page.
I know but I think that happens after it is processed by php-exe.
>>What exactly do you want to merge into the page each time it is called?
Values from Clarion database (tps). I use tokens that are filled out at runtime and these could be used in the PHP-code.
Example: if you need to setup a connection with a PSP for processing credit cards, paypal and other payment options
the PSP gives you free PHP (or ASP etc) code that does the job.
In Clarion you have to build it up from scratch.
So it could be handy to use PHP but it needs some values at runtime that can't be hardcoded.
Of course you can setup things in SQL and let the PHP code retrieve the information but that is another interesting approach.
Regards,
Nick
-
>> I know but I think that happens after it is processed by php-exe.
This is correct. So you cannot use the <!-- Net:s:SessionVariable --> tag to get the values.
There are two ways to include the data you want in the php page:
1) Add the data onto the end of the URL when you are calling the php page: ProcessCreditCard.php?variable1=this&variable2=that
If you are using a button to call the php page this would be set as:
URL: ProcessCreditCard.php
Parameters: 'variable1='& p_web.GSV('this') &'&variable2='& p_web.GSV('that')
The in the php page you can get the values and set them as php variables like this:
$this = $_GET["variable1"];
$that = $_GET["variable2"];
This isn't very secure unless you encrypt the data in the variables before calling the php page and then decrypt the data inside the php page. Or you could use https.
2) Save the details into an SQL database and retrieve the values in php. The example I provided in the previous post shows you how to do this.
Regards,
Trent
-
Thanks for your thoughts!
Still I would like to know (Bruce?) at which code-point the .php page will be send to the php-exe (by using OddJob I guess).
If it is the content of the page that triggers NT to feed it to the php-exe as you said then NT must first examine the
page-content.
Nick
-
Hi Nick,
All the interaction between the WebServer and the PHP exe takes place in the _SendPhpFile method in the web handler. You can inspect the code in the netweb.clw method.
The highlights are that the file name is passed to the PHP Exe (so you can't really pre-process the PHP page). However what you can manipulate id the p_web.WholeURL property. This contains the "parameters" which the PHP page then applies. So you could "extend" this URL with your own parameters, and then access those parameters in the PHP code.
The output from the PHP engine is fed through the ParseHTML method - and that in turn explodes all the tags (like Net:s and so on...)
Cheers
Bruce
-
Hi Bruce,
Thanks!
Nick