DataLife Engine > Scripts > API whois + registration handler based on PHP
API whois + registration handler based on PHP29 августа 2008. Разместил: Barthez |
![]() Description: Are you an experienced PHPer and do you want to integrate our service smoothly into your PHP scripts? Look no further, our API has been made exactly for that. By using our API you can easily improve your site by adding another service or feature: free domain names. Below are some howto and script examples of how to use our API in your PHP scripts. We also recommend you to carefully examine the complete example script at the bottom of the page after reading all steps. Use of this API is completely free of charge. p.S: Good Luck. <?php //start sessions session_start(); //there are 3 phases in this script: domain check phase (1), input phase (2) and finish phase (3) - if no phase set, set phase to 1 If (!isset($_SESSION['phase'])) { $_SESSION['phase'] = 1; } //if form has been submitted and phase = 1 If (($_SERVER['REQUEST_METHOD']=='POST') AND ($_SESSION['phase'] == 1)) { $_SESSION['domain'] = $_POST['domain']; //get posted value $send = 1; //form has been send $whois = file_get_contents("http://nl.ae/domainapi/whois.php?domain=".$_SESSION['domain']); //check whether the domain is available, returns 1 or 0 If ($whois) { //$whois is 1, so the domain is still available, go to phase 2 to let user fill in details $_SESSION['phase'] = 2; } ElseIf ($whois == 0) { //the domain is unavailable for registration $domain_error = "Sorry, ".$_SESSION['domain'].".nl.ae is unavailable for registration, please choose an other domain."; } Else { //this should not happen - maybe your server is running PHP on safe mode (or file_get_contents is otherwise disabled)? $domain_error = "An unknown error occured during registration, please try again later. Please contact the server admin if this problem persists."; } } ElseIf (($_SERVER['REQUEST_METHOD']=='POST') AND ($_SESSION['phase'] == 2)) { //if form has been submitted and phase = 2 //store all posted values in sessions so we can use them again if needed $_SESSION['url'] = $_POST['url']; $_SESSION['email'] = $_POST['email']; $_SESSION['category'] = $_POST['category']; $_SESSION['title'] = $_POST['title']; $_SESSION['description'] = $_POST['description']; $_SESSION['keywords'] = $_POST['keywords']; $_SESSION['favicon'] = $_POST['favicon']; $_SESSION['language'] = $_POST['language']; $_SESSION['revisit'] = $_POST['revisit']; $_SESSION['robots'] = $_POST['robots']; $send = 1; //form has been send //send request to nl.ae server and receive answer in $domapi $domapi = file_get_contents("http://nl.ae/domainapi/register.php?id=".$_SESSION['apiid']."&captcha=".$_POST['captcha']."&domain=".$_SESSION['domain']."&url=".$_SESSION['url']."&email=".$_SESSION['email']."&category=".$_SESSION['category']."&title=".$_SESSION['title']."&description=".$_SESSION['description']."&keywords=".$_SESSION['keywords']."&favicon=".$_SESSION['favicon']."&language=".$_SESSION['language']."&revisit=".$_SESSION['revisit']."&robots=".$_SESSION['robots']); If ($domapi == 1) { //everything went alright, domain registered -> phase 3 $_SESSION['phase'] = 3; } ElseIf ($domapi == 0) { //ID was not given (you must have made a mistake in your script) $domain_error = "Webmaster has forgotten to use the Anti-Bot CAPTCHA ID correctly, please contact the admin of this website."; } ElseIf ($domapi == -1) { //no CAPTCHA was given by user $domain_error = "Please type over the code in the Anti-Bot CAPTCHA image to the inputfield."; } ElseIf ($domapi == -2) { //invalid CAPTCHA $domain_error = "You haven't typed over the Anti-Bot CAPTCHA code correcly, please try again."; } ElseIf ($domapi == -3) { //invalid or empty domain given $domain_error = "Please enter a valid domain."; } ElseIf ($domapi == -4) { //domain is unavailable for registration $domain_error = "This domain is unavailable for registration, please choose an other domain."; } ElseIf ($domapi == -5) { //invalid URL $domain_error = "Please enter a valid URL starting with http://, https://, www., callto://, callto:, mailto://, mailto: or irc://. It must have less then 2048 characters."; } ElseIf ($domapi == -6) { //invalid e-mail address $domain_error = "Please fill in a valid e-mail address. You need it to activate your domain."; } ElseIf ($domapi == -7) { //invalid category $domain_error = "Please choose a valid category for your domain."; } ElseIf ($domapi == -8) { //invalid title $domain_error = "You have entered an invalid title. It must have more then 2 and less then 100 characters."; } ElseIf ($domapi == -9) { //invalid description $domain_error = "You have entered an invalid description. It may not have more then 150 characters."; } ElseIf ($domapi == -10) { //invalid keywords $domain_error = "You have entered invalid keywords. You may not enter more then 380 characters."; } ElseIf ($domapi == -11) { //invalid favicon $domain_error = "You have entered an invalid favicon path. It must start with http:// or https://. It must end with .ico and may not contain more then 500 characters."; } ElseIf ($domapi == -12) { //invalid language $domain_error = "You have entered an invalid language. It may not contain more then 50 characters."; } ElseIf ($domapi == -13) { //invalid revisit $domain_error = "You have entered an invalid revisit value. It may not be less then 3 or more then 999. Enter a 0 or leave this field blank to let search engines decide (recommended)."; } ElseIf ($domapi == -14) { //invalid robots $domain_error = "You have entered an invalid robots value. It may not have more then 50 characters."; } Else { //this should not happen - maybe your server is running PHP on safe mode (or file_get_contents is otherwise disabled)? $domain_error = "An unknown error has occured, please try again later."; } } ?> <h2>nl.ae domain registration example script</h2> <?php If ($_SESSION['phase'] == 1) { //if phase 1 show domain whois form ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php If((isset($send)) AND ($send == 1)) { If(isset($domain_error)) { echo "<p style='color: red;'>".$domain_error."</p>"; } } ?> <p>www.<input type="text" maxlength="50" size="20" id="domain" name="domain" value="domain" />.nl.ae</p> <input class="button" type="submit" value="check!" /> </form> <?php } ElseIf ($_SESSION['phase'] == 2) { //if phase 2 show domain information input form $_SESSION['apiid'] = file_get_contents("http://nl.ae/domainapi/reqid.php"); //identify with nl.ae server, used for CAPTCHA below ?> <p>Congratulations, this domain is still available for registration. Please fill in the details below.</p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php If((isset($send)) AND ($send == 1)) { If(isset($domain_error)) { echo "<p style='color: red;'>".$domain_error."</p>"; } } ?> <p><b>Required Fields (these must be filled in)</b><br /> Domain: www.<?php echo $_SESSION['domain']; ?>.nl.ae<br /> Redirect URL: <input type="text" id="url" name="url" value="<?php if (isset($_SESSION['url'])) { echo $_SESSION['url']; } else { echo "http://"; } ?>" /><br /> E-mail address: <input type="text" id="email" name="email" value="<?php if (isset($_SESSION['email'])) { echo $_SESSION['email']; } else { echo "email@address.com"; } ?>" /><br /> Category: <select id="category" name="category"> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "none")) { echo 'selected="selected"'; } ?> value="none">Choose --></option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "blogs")) { echo 'selected="selected"'; } ?> value="blogs">Blogs</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "business")) { echo 'selected="selected"'; } ?> value="business">Business</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "computers")) { echo 'selected="selected"'; } ?> value="computers">Computers and Internet</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "education")) { echo 'selected="selected"'; } ?> value="education">Education</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "entertainement")) { echo 'selected="selected"'; } ?> value="entertainement">Entertainement</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "games")) { echo 'selected="selected"'; } ?> value="games">Games</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "health")) { echo 'selected="selected"'; } ?> value="health">Health</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "literature")) { echo 'selected="selected"'; } ?> value="literature">Literature and Culture</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "miscelaneous")) { echo 'selected="selected"'; } ?> value="miscelaneous">Miscelaneous</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "multimedia")) { echo 'selected="selected"'; } ?> value="multimedia">Multimedia</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "religion")) { echo 'selected="selected"'; } ?> value="religion">Religion</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "science")) { echo 'selected="selected"'; } ?> value="science">Science</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "society")) { echo 'selected="selected"'; } ?> value="society">Society</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "sport")) { echo 'selected="selected"'; } ?> value="sport">Sport</option> <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "teen")) { echo 'selected="selected"'; } ?> value="teen">Teen</option> </select><br /></p> <p><b>Optional Fields (these can be left empty)</b><br /> Domain title: <input type="text" id="title" name="title" value="<?php if (isset($_SESSION['title'])) { echo $_SESSION['title']; } else { echo "Welcome to my site!"; } ?>" /><br /> Description: <input type="text" id="description" name="description" value="<?php if (isset($_SESSION['description'])) { echo $_SESSION['description']; } ?>" /><br /> Keywords: <input type="text" id="keywords" name="keywords" value="<?php if (isset($_SESSION['keywords'])) { echo $_SESSION['keywords']; } ?>" /><br /> Favicon: <input type="text" id="favicon" name="favicon" value="<?php if (isset($_SESSION['favicon'])) { echo $_SESSION['favicon']; } else { echo "http://nl.ae/images/favicon.ico"; } ?>" /><br /> Language: <input type="text" id="language" name="language" value="<?php if (isset($_SESSION['language'])) { echo $_SESSION['language']; } ?>" /><br /> Revisit: <input type="text" id="revisit" name="revisit" value="<?php if (isset($_SESSION['revisit'])) { echo $_SESSION['revisit']; } else { echo 0; } ?>" /> days<br /> Robots: <input type="text" id="robots" name="robots" value="<?php if (isset($_SESSION['robots'])) { echo $_SESSION['robots']; } else { echo "index, follow"; } ?>" /></p> <p><b>Anti-Bot Verification</b><br /> Please copy the code shown in the image to the inputfield below.<br /> <img src="http://nl.ae/domainapi/captcha.php?id=<?php echo $_SESSION['apiid']; // the ID received earlier this session (see above)?>" title="Please copy the code shown in the image to the inputfield below." /><br /> <input type="text" id="captcha" name="captcha" value="" /> </p> <input class="button" type="submit" value="register domain!" /> </form> <?php } ElseIf ($_SESSION['phase'] == 3) { //if phase 3 show confirmation page $_SESSION['phase'] = 1; //reset phase to 1 so user can register a new domain on refresh ?> <p>Congratulations! Your domain has been registered succesfully. Please login at <a href="http://www.login.nl.ae">www.login.nl.ae</a> using the account information send to your e-mail address to activate your domain. Your domain will be automatically removed if it is not activated within 7 days. We thus recommend you to activate it immediately.</p><p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Register another domain!</a></p> <?php } ?> |

