Saturday, 23 August 2008

Connecting to Nominet EPP with PHP

EPP stands for Extensible Provisioning Protocol, this is the method that a large number of domain registries use to communicate.

This is a basic example of how to connect to an EPP server using a basic script supplied by CentralNic.

The script, Net_EPP_Client can be downloaded from CentralNic Labs and can be installed using PEAR or manually by copying into the relevant directory.

For the examples in the post, we will be logging into the Nominet EPP server.

EPP clients connect to a server, login and then send the commands that wish to make. An example of connecting is as follows:

<?php
require('Net/EPP/Client.php');

$client = new Net_EPP_Client;
$host = 'epp.nominet.org.uk';
$port = 700;
$timeout = 10;
$ssl = true;

$greeting = $client->connect($host, $port, $timeout, $ssl);

echo $greeting;
?>
Which will output

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/epp-1.0 epp-1.0.xsd">
<greeting>
<svID>Nominet EPP server epp.nominet.org.uk</svID>
<svDate>2008-08-23T16:24:51Z</svDate>
<svcMenu>
<version>1.0</version>
<lang>en</lang>
<objURI>http://www.nominet.org.uk/epp/xml/nom-account-1.0</objURI>
<objURI>http://www.nominet.org.uk/epp/xml/nom-domain-1.0</objURI>
<objURI>http://www.nominet.org.uk/epp/xml/nom-contact-1.0</objURI>
<objURI>http://www.nominet.org.uk/epp/xml/nom-ns-1.0</objURI>
</svcMenu>
<dcp>
<access><all/></access>
<statement>
<purpose><admin/><prov/></purpose>
<recipient><ours/></recipient>
<retention><indefinite/></retention>
</statement>
</dcp>
</greeting>
</epp>

This shows that the connection is correctly opened and you are now able to login by sending back the following reply:

<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<login>
<clID>TAG_NAME</clID>
<pw>password</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>http://www.nominet.org.uk/epp/xml/nom-account-1.0</objURI>
<objURI>http://www.nominet.org.uk/epp/xml/nom-domain-1.0</objURI>
<objURI>http://www.nominet.org.uk/epp/xml/nom-contact-1.0</objURI>
<objURI>http://www.nominet.org.uk/epp/xml/nom-ns-1.0</objURI>
</svcs>
</login>
<clTRID>your_transaction_id</clTRID>
</command>
</epp>

I find that an easy way to manage creating EPP XML requests is by using the Smarty templating system, more on that in a later post.

You should then receive a reply indicating your login was successful:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nominet.org.uk/epp/xml/epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg>
Command completed successfully
</msg>
</result>
<trID>
<clTRID>EPP-your_transaction_id</clTRID>
<svTRID>12345678</svTRID>
</trID>
</response>
</epp>

From there you can go on to perform the actions you require, more information on using Nominet's EPP service can be found at http://www.nic.uk/registrars/systems/epp/

2 comments:

Anonymous said...

Hi,

Can you help me? I got the following error message:

PHP Notice: Undefined variable: errno in /usr/share/pear/Net/EPP/Client.php on line 58

PHP Catchable fatal error: Object of class PEAR_Error could not be converted to string in /var/www/rnd-html/nominet/connect.php on line 12

deepak said...

Hi thanks for posting this....
can u please more explain it actually when i m connecting it ,it is giving the error
Error connecting to ssl://epp.nominet.org.uk:700: 0 (code )