I got a new wallpaper of PHP Warior. This is cool when I keep it as desktop background

Click here for higher resolution: http://www.deviantart.com/deviation/38526422/
I got a new wallpaper of PHP Warior. This is cool when I keep it as desktop background

Click here for higher resolution: http://www.deviantart.com/deviation/38526422/
SOAP is a protocol for applications and servers to communicate with each other. Its primary use in PHP is exposing Web services and building Web service clients. As a protocol, it can exchange messages over HTTP/HTTPS, which helps it get around firewalls that would block other protocols (eg, Remote Procedure Call). As an application layer protocol, SOAP is also entirely platform independent — your PHP Web application can talk to a Java database server, for example, as long as they both speak SOAP.
SOAP messages are simply XML with some custom namespaces, so they’re fully machine-readable. Libraries are available for every major language, and working with SOAP Web services is quick, easy and fast.
we’re going to take a look at one of these libraries, NuSOAP. PHP has a few options for SOAP, including a PHP 5 extension, a PEAR package, and an independent (but very popular) library called NuSOAP. NuSOAP is the simplest way to get up and running with SOAP, but we could just as well have used PEAR::SOAP or the extension, and all three are interoperable — you can consume PEAR::SOAP exposed services with NuSOAP and vice versa, and scripts using either can happily run alongside each other.
Getting started with NuSOAP
All examples should be forwards-compatible, but API changes happen, so check your library version if you encounter any errors. Drop the contents of the archive into a folder on your Web server — using /soap under my docroot. The latest version is compatible with the SOAP extension, but if you experience “class already declared” errors just disable the SOAP extension or rename the class in nusoap.php.
Your first SOAP request!
Lets begin with the SOAP. SOAP works with servers and clients. We’ll start with a demo of a simple Web service that takes an argument and returns an array
<?php
include("lib/nusoap.php");
$soap = new soapclient("http://127.0.0.1/soap/hello_world_server.php");
// You can give localhost also in place of IP 127.0.0.1
$output = $soap->call("hello_world", array("name" => "Josh"));
print_r($output);
Save it as helloworld.php in the folder you created earlier. It can be anywhere, as long as the lib/nusoap.php reference still points to your NuSOAP library. Do the same for the server:
<?php
include("lib/nusoap.php");
$srv = new soap_server();
$srv->register("hello_world");
function hello_world($name)
{
return array("data"=>"Hello World, {$name}!");
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : "";
$srv->service($HTTP_RAW_POST_DATA);
Save this as helloworldserver.php in the same folder. If it can’t be accessed at that URL in the client script (localhost/soap/…), change the reference in the client code as needed.
Then load up your Web browser, point it to the SOAP client — eg, http://localhost/soap/helloworld.php — and run the script. You should see the following:
Array
(
[data] => Hello World, Josh!
)
That’s perfectly normal print_r output — precisely what you would expect if you returned the array within the same PHP script. Except that our server script is separate, could be on a different server and could be running on a totally different platform — SOAP helps gets data from the server to the client as smoothly as possible.
The Server
Let’s examine the server for a moment. Here’s the code we used to build our server:
<?php
include("lib/nusoap.php");
$srv = new soap_server();
$srv->register("hello_world");
function hello_world($name)
{
return array("data"=>"Hello World, {$name}!");
}
In this example, we first load up the NuSOAP library and register the service we want to expose, naming it “hello_world”. We then define this service as a standard PHP function. At the moment, it does nothing but return a simple associative array, with the value containing an argument, $name. The client provides this argument from a totally separate PHP script and SOAP provides the glue to make sure it is passed in when the function is called.
HTTP is stateless, and our PHP script will be executed from the top down whenever a request is made, so each SOAP call (or other script execution) will be a new request. To check if we have a SOAP call (and what the SOAP client wants us to do), we have to scan each request for data. SOAP clients send POST requests, with XML data in the message body of the request, so we can fetch this raw POST data and pass it to the service() method of the soap_server class. Raw POST data is available in $HTTP_RAW_POST_DATA, but PHP won’t set this unless it has a value, so we use a small hack to ensure it exists before passing it on to the SOAP server.
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$srv->service($HTTP_RAW_POST_DATA);
We quickly get together the raw POST data, pass it to the SOAP library, and away we go.
The Client
The client uses the NuSOAP library, but only because we choose to — the server could use the PHP SOAP extension or PEAR::SOAP, and could be hosted anywhere. With the power of SOAP, we’re going to take the PHP function on the server and talk to it through SOAP; we’re also going to receive the result just like any other variable within our script. Have a look at the code for the client:
<?php
include("lib/nusoap.php");
$soap = new soapclient("http://127.0.0.1/soap/hello_world_server.php");
$output = $soap->call("hello_world", array("name" => "Josh"));
print_r($output);
The client is very basic — we first load up the library, then establish a connection to the SOAP server at the URL we’ve provided and call the “hello_world” service. For testing, we’ll print_r the output. The second argument to the $soap->call() method is an array of parameters to be passed to the service. Notice we specify ‘name’ as the array key, the same as the $name argument on the server’s function — this is not necessary as we aren’t working with complex pre-defined services, however, it does hold importance when consuming slightly more elaborate SOAP services.
The service call returns a value which we then put into $output. If we check that print_r output earlier, it showed we had a perfectly good PHP associative array — [data] => Hello World, Josh! — just as our server’s hello_world() function should have returned. In just a few lines of code, we’ve linked together two independent PHP scripts. Now your Web apps are really talking.
Behind the scenes: debugging SOAP
While you make high-level calls to the SOAP libraries, the NuSOAP library is actually busy generating and parsing XML request messages and passing them back and forth between server and client. You can easily examine the message body of your request and the server’s response on the client side, using the request and response properties of the SOAP client class. These are invaluable in debugging, and will help you get a better understanding of SOAP internals, although you may never need it…
<?php
include("lib/nusoap.php");
$soap = new soapclient("http://127.0.0.1/soap/hello_world_server.php");
$output = $soap->call("hello_world", array("name" => "Josh"));
print_r($output);
echo '<pre>'.htmlspecialchars($soap->request).'</pre>';
echo '<pre>'.htmlspecialchars($soap->response).'</pre>';
This request will output something like the following:
POST /soap/hello_world_server.php HTTP/1.0
Host: 127.0.0.1
User-Agent: NuSOAP/0.7.2 (1.94)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 511
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope ...
Notice we’re making a direct POST request and passing all the XML through. In a HTML form request, that XML would be replaced with key=value&key=value pairs, which are then translated into elements of $_POST — this is why we have to request the raw POST data to check for a SOAP request. The actual XML schema for SOAP messages isn’t important, as the libraries take care of it for us, but read up on the SOAP specifications if you want to take a closer look.
Further SOAP
Now that you’ve built your first SOAP client, experiment with more complex APIs, or try consuming one of the many SOAP-based APIs available. If your applications already receive data from other sources, check if they offer SOAP — its use is very prevalent in enterprise situations, especially where SOA is encouraged. Finally, if you want to learn more about NuSOAP, one of the authors provides some handy resources.
Reference: http://www.builderau.com.au
Have you thought of creating excel files using PHP?
You use these classes to generate your excel files. Pretty simple, but very effective.
Start with downloading (registrate for free to download), here http://www.phpclasses.org/browse/package/1919.html .
Unzip and upload the file named excel.php to your server.
I am going to generate a simple excel file that will contain Name and IQ in two columns
The file will look something like this (Hopefully):
First name IQ
John 2250
Ram 1200
Steve 1200
Vinod 1200
Create the php file that will create the excel files for you.
Lets call it: excelgenerate.php
Start with:
require_once “excel.php”;
$filename = “theFile.xls”;
This section will create and save the excel file on the server.
The file will be saved in the directory tmp, as theFile.xls.
The code is pretty self explaining I think. don’t bother with small details, just use it as a tool!
$export_file = “xlsfile://tmp/”.$filename;
$fp = fopen($export_file, “wb”);
if (!is_resource($fp))
{
die(”Cannot open $export_file”);
}
// typically this will be generated/read from a database table
$assoc = array(
array(”First name” => “John”, “IQ” => 2250,
array(”First name” => “Ram”, “IQ” => 1200,
array(”First name” => “Steve”, “IQ” => 1200,
array(”First name” => “Vinod”, “IQ” => 1200);
fwrite($fp, serialize($assoc));
fclose($fp);
This section is for opening the file directly for the surfer in his browser.
It’s then up to the user to choose if he/she wants to open or save the file.
If you only want to save files on the server, just remove this part from the file.
header (”Expires: Mon, 26 Jul 1997 05:00:00 GMT”);
header (”Last-Modified: ” . gmdate(”D,d M YH:i:s”) . ” GMT”);
header (”Cache-Control: no-cache, must-revalidate”);
header (”Pragma: no-cache”);
header (”Content-type: application/x-msexcel”);
header (”Content-Disposition: attachment; filename=\”” . $filename . “\”” );
header (”Content-Description: PHP/INTERBASE Generated Data” );
readfile($export_file);
exit;
If you run this code you will get two things:
1. An excel file in /var/ on your server
2. This file opened to the user that surf your site
Refrence: PHPClasses.com
The .NET development framework facilitates writing applications in more than one programming language like VB or C#. While writing a .NET application, you can always opt for a language of our choice. You can even write each module (say a Windows form or a Web form) of an application in a different language. On the other hand, PHP is a popular open
source scripting language which is used typically for writing Web based applications. Being a scripting language, applications written in PHP are interpreted and not compiled.
With a piece of software/plugin called Phalanger, you can use PHP as one of the languages for writing .Net applications. Plus these applications, written in PHP will be compiled ? as with any application written in .NET language. Plus, Phalanger offers an extension/plugin for Visual Studio which allows you to write PHP based .Net applications in Visual Studio 2008 (the latest in the Visual Studio family).
Get, set and go…
Assuming that you have already installed and are running .NET 2.0 (or above) framework and Visual Studio 2008, you require to do the following to download and install Phalanger:
1. Download phalanger-2.0-march-2008.zip from the URL http://www.codeplex.com/Phalanger/Release/ProjectReleases.aspx?ReleaseId=11564#ReleaseFiles.
2. Unzip the file and run the installer via setup.exe. The installer also sets up IIS web server for PHP (to be precise, for PHP Phalanger).
3. To write PHP Phalanger applications in Visual Studio, you need to install the Phalanger extension which is a separate download.
4. Go to the above mentioned link and download the file vsintegration-2.0-march-2008.zip. Unzip the file and run vsiip.msi.
Configure IIS Web Server
To configure IIS on Windows XP to use Phalanger, execute the following steps:
1. Goto Control Panel>Administrative Tools>Internet Information Services.
2.Expand the tree (in the left pane) till you see ?Default Web Site?. Right click on it and select Properties.
3.Click on the ?Home Directory? tab and then click on the Configuration button. Under the Mappings tab, click on Add. Type in the following for the Executable and the Extension:
Executable: C:\WINDOWS\ Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
Extension: .php
4. Leave the other settings to their default. Restart IIS.
![]() |
| Besides web applications, you can write assembly/class libraries, console applications and Windows forms based applications using Visual Studio as the RAD tool and PHP as the language. |
Hello Phalanger
Let us write a simple Hello Phalanger web page. Type in the following code in a text editor (like Notepad):
<?php
print(?Hello Phalanger?);
?>
Save the above file as hello.php in c:\inetpub\wwwroot. Browse to the web page at http://localhost/hello.php and you will be greeted by a ?Hello Phalanger? message. Note that we did not install PHP (from www.php.net) or PHP ISAPI DLL or PHP CGI. Phalanger has taken over as the scripting engine for .php files. It compiles and displays the output of the PHP code.
With the Phalanger extension for Visual Studio, you can write the above mentioned Phalanger page in Visual Studio. Now we need to start Visual Studio 2008. For this, click on File->New Website. Select PHP from the language dropdown and then select Phalanger PHP Web. This will open a new Visual Studio project which will include a file named default.php. Type in the above print( ) statement in default.php.
Right click on the Website in the Solution Explorer and select ?View in browser?. This will launch Visual Studio’s built in web server and will show a page with the files. Click on default.php to see the output.
Debugging Phalanger apps in Visual Studio
Before you debug Phalanger apps, you need to take care of the following. In the debug mode, Visual Studio does not show the runtime values of PHP variables on mouse over. Instead you will need to use the Locals window.
To inspect the runtime values of PHP variables, you will need to launch the Locals window, while in debug mode, via Debug>Windows>Locals. In this window, you can spot the local (to a function) variables. To look at global variables, expand the <context> tree and you will see the runtime values of the global PHP variables under Global Variables.
PHP Assembly in C# applications
After the Hello Phalanger program, lets look at something more interesting. What if one can write assemblies (or class libraries) in PHP which in turn can be used in .Net applications (Web or Desktop)? This will prove useful if you have an existing investment done in a complicated logic written in PHP and now want to use the same logic in a .Net application.
As a simple example, we write a PHP class library named Cryto which has a function/method called GetMD5(). This function simply accepts a string, uses PHP’s inbuilt MD5 function and returns the MD5 hash of the string.
In Visual Studio, click on File>New Project. Under the ?Project Types? menu, select Phalanger. From the right pane, select Phalanger Class Library. For the project name, type in Crypto and then click on Ok button. Now go to the the Solutions Explorer and here click on the Library.php, which will look like this:
class Library
{
function __construct()
{
}
}
You need to modify the code to the following:
<?
[Export]class Crypto
{
function __construct()
{
}
function GetMD5($str) {
return md5($str);
}
}
?>
Now build the project and create a new .Net Web application in C#. Right click on the Project and click on Add Reference. Then browse to the assembly file (Crypto.dll) of Crypto. The assembly file can be found, typically, in My Documents\Visual Studio 2008\Projects\Crypto\Crypto\bin\Debug. You will also need to add a reference to PhpNetCore.dll (found in Program Files\Phalanger\Bin directory).
Now in the code behind (Default.aspx.cs, for example), you can call the the GetMD5() function, of the assembly written in PHP. This can be done as shown below:
Crypto crypto = new Crypto();
string str = (string)crypto.GetMD5(“Hello Phalanger”);
Response.Write(str);
To explore more about Phalanger plug-in, browse to the site http://php-compiler.net/doku.php and learn more about other nifty uses that you can put this software for.
to your autoexec.bat. On NT add
to the end of the PATH environment variable. It is also important to note in your autoexec.bat file, the PHP Java extension ignores the JAVA_HOME and CLASSPATH set up in the environment. This is important because these items must be set correctly in your php.ini file for the Java extension to work.
[java] extension=php_java.dll java.library.path=c:\web\php4\extensions\ java.class.path="c:\web\php4\extensions\jdk1.2.2\php_java.jar;c:\myclasses"
extension=php_java.dll directive with the rest of the extensions, but it can sit happily under [java]. The java.library.path must be set in the location of the php_java.dll, and java.class.path must include the location of php_java.jar. The java.class.path should also include the path to other classes you may wish to use (note the double quotes!). In these examples, we will be talking about c:\myclasses. You should also note that the single period is ignored by PHP and Java. As far as we know, you cannot set PHP to look in the current directory for its Java classes.<?php
$system = new Java("java.lang.System");
print "Java version=".$system->getProperty("java.version")." <br>\n";
print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n";
print "OS=".$system->getProperty("os.name")." ".
$system->getProperty("os.version")." on ".
$system->getProperty("os.arch")." <br>\n";
$formatter = new Java("java.text.SimpleDateFormat","EEEE,
MMMM dd, yyyy 'at' h:mm:ss a zzzz");
print $formatter->format(new Java("java.util.Date"))."\n";
?>
Java version=1.2.2 Java vendor=Sun Microsystems Inc. OS=Windows 2000 4.10 on x86 Wednesday, June 18, 2009 at 10:22:45 AM India Standard Time
The more and more you see and read about how other websites are using SMS, the more and more you begin to wonder why you’re not. So I’ll show you how (in PHP, because it’s the only language i know!). Although it is possible to send SMS via e-mail, which I might cover another time.
This tutorial focuses on the use of HTTP methods “get” & “post”. For those of us that may not know this, using HTTP basically means the use of forms, except that these will be submitted automatically as opposed to manually.
Although this tutorial can be used for any gateway that provides access via HTTP, this tutorial is based on the TM4B Bulk SMS Gateway because:
Any SMS gateway will provide details about how you can connect up to them. In the case of TM4B, these are provided on their SMS API page. They basically require us to provide six mandatory pieces of data:
They will be expecting us to send our messages to them via HTTP requests, similar to this:
http://www.tm4b.com/client/api/send.php?
username=abcdef&password=12345&msg=
This+is+sample+message.&to=447768254545%7C447956219273%
7C447771514662&from=MyCompany&route=frst&sim=yes
which you can test by clicking on it or pasting it into your browser’s address bar.
The first step we have to take is to store our data as variables and then convert them into a url request. There are different ways of doing this, but this is a very innovative and useful way borrowed from the TM4B site itself:
<?php
$request = "";
//initialise the request variable
$param[username] = "abcdef";
//this is the username of our TM4B account
$param[password] = "12345";
//this is the password of our TM4B account
$param[msg] = "This is sample message.";
//this is the message that we want to send
$param[to] = "447768254545|447956219273|447771514662";
//these are the recipients of the message
$param[from] = "MyCompany";
//this is our sender if
$param[route] = "frst";
//we want to send the message via first class
$param[sim] = "yes";
//we are only simulating a broadcast
foreach($param as $key=>$val)
//traverse through each member of the param array
{
$request.= $key."=".urlencode($val);
//we have to urlencode the values
$request.= "&";
//append the ampersand (&) sign after each paramter/value pair
}
$request = substr($request, 0, strlen($request)-1);
//remove the final ampersand (&) sign from the request
/*This will produce the following request:username=abcdef&password=12345&
msg=This+is+sample+message.&to=447768254545%7C447956219273%
7C447771514662&from=MyCompany&route=frst&sim=yes */
?>
In step 0, we saw that the request could be actioned by pasting it into the browser window. But what we really want is for this to take place behind the scenes and we wouldn’t want anyone knowing our username and password.
The following 2 pieces of code do exactly that. They open up a connection with the gateway, send the SMS message(s) and collect their message ID’s which are presented within the response header.
<?php
//First prepare the info that relates to the connection
$host = "tm4b.com";
//although you can use an ip address, it is easier to just use tm4b.com
$request_length = strlen($request);
// when we post the header, we have to also include it's length
$script = "/client/api/send.php";
$method = "POST";
//Replace with "GET" if required.
if($method=="GET") $script .= "?$request";
//Appends the request if "GET" is being used.
//Now comes the header which we are going to post. This is where our messages details will be sent over.
$header = "$method
$script HTTP/1.1rn".
//"Host: $hostrn". "User-Agent: HTTP/1.1rn". "Content-Type: application/x-www-form-urlencodedrn". "Content-Length: $request_lengthrn". "Connection: closernrn". "$requestrn";
//Now we open up the connection
$socket = @fsockopen($host, 80, $errno, $errstr);
if ($socket) //if its open, then...
{ fputs($socket, $header);
// send the details over
while(!feof($socket)) $output[] = fgets($socket);
//get the results
fclose($socket);
}
//print_r($output);
//the message id's will be kept in one of the $output values
?>
Whilst fsockopen may be more familar to most of us, it can only handle non-secure URL’s. Furthermore, difficulty may be experienced when parsing responses for large requests (i.e. hundreds of messages) as the response is transferred in chunks.
Whilst “Curl” might sound new, it is a really cool way of connecting and communicate to many different types of servers. You can find more info in the PHP Manual.
<?php
$url = https://www.tm4b.com/client/api/send.php;
//although we have used https, you can also use http
$ch = curl_init();
//initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url);
//set the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
//return as a variable
curl_setopt($ch, CURLOPT_POST, 1);
//set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
//set the POST variables
$response = curl_exec($ch);
//run the whole process and return the response
curl_close($ch);
//close the curl handle
//print $response;
//show the result onscreen for debugging
?>
That’s It!!! No more. Now you should know how to send one or more SMS messages through an SMS Gateway. By the way, I think Curl is the better, neater and quicker option of the two (assuming your version of PHP supports it) as it can send thousands of messages in one go, gives no problems in parsing the message ID’s and uses either a secure or non-secure url.