login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Zoekmachines > nl.ae domein whois + registratie API handler

nl.ae domein whois + registratie API handler

Auteur: tommedema - 05 augustus 2008 - 21:36 - Gekeurd door: Gerard - Hits: 3259 - Aantal punten: (0 stemmen)



Het volgende script maakt gebruik van een Application Programming Interface (API) om .nl.ae domeinen te controleren en wanneer gewenst te registreren.

Het is mogelijk om slechts één van bovenstaande acties uit te voeren, je kunt het script dan ook naar je eigen wensen aanpassen. Zie http://www.api.nl.ae voor meer informatie, voorbeelden en uitleg.

Dit is niet zomaar een API, deze maakt namelijk gebruik van een externa CAPTCHA. Het is daarom eerst nodig een identifier van de server op te halen, welke je vervolgens meegeeft aan de dynamische afbeelding (captcha). Zie de comments in het script voor uitleg.

Code:
  1. <?php
  2. //start sessions
  3.  
  4. //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
  5. If (!isset($_SESSION['phase'])) {
  6. $_SESSION['phase'] = 1;
  7. }
  8.  
  9. //if form has been submitted and phase = 1
  10. If (($_SERVER['REQUEST_METHOD']=='POST') AND ($_SESSION['phase'] == 1)) {
  11. $_SESSION['domain'] = $_POST['domain']; //get posted value
  12. $send = 1; //form has been send
  13. $whois = file_get_contents("http://nl.ae/domainapi/whois.php?domain=".$_SESSION['domain']); //check whether the domain is available, returns 1 or 0
  14. If ($whois) { //$whois is 1, so the domain is still available, go to phase 2 to let user fill in details
  15. $_SESSION['phase'] = 2;
  16. }
  17. ElseIf ($whois == 0) { //the domain is unavailable for registration
  18. $domain_error = "Sorry, ".$_SESSION['domain'].".nl.ae is unavailable for registration, please choose an other domain.";
  19. }
  20. Else { //this should not happen - maybe your server is running PHP on safe mode (or file_get_contents is otherwise disabled)?
  21. $domain_error = "An unknown error occured during registration, please try again later. Please contact the server admin if this problem persists.";
  22. }
  23. }
  24. ElseIf (($_SERVER['REQUEST_METHOD']=='POST') AND ($_SESSION['phase'] == 2)) { //if form has been submitted and phase = 2
  25. //store all posted values in sessions so we can use them again if needed
  26. $_SESSION['url'] = $_POST['url'];
  27. $_SESSION['email'] = $_POST['email'];
  28. $_SESSION['category'] = $_POST['category'];
  29. $_SESSION['title'] = $_POST['title'];
  30. $_SESSION['description'] = $_POST['description'];
  31. $_SESSION['keywords'] = $_POST['keywords'];
  32. $_SESSION['favicon'] = $_POST['favicon'];
  33. $_SESSION['language'] = $_POST['language'];
  34. $_SESSION['revisit'] = $_POST['revisit'];
  35. $_SESSION['robots'] = $_POST['robots'];
  36. $send = 1; //form has been send
  37. //send request to nl.ae server and receive answer in $domapi
  38. $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']);
  39. If ($domapi == 1) { //everything went alright, domain registered -> phase 3
  40. $_SESSION['phase'] = 3;
  41. }
  42. ElseIf ($domapi == 0) { //ID was not given (you must have made a mistake in your script)
  43. $domain_error = "Webmaster has forgotten to use the Anti-Bot CAPTCHA ID correctly, please contact the admin of this website.";
  44. }
  45. ElseIf ($domapi == -1) { //no CAPTCHA was given by user
  46. $domain_error = "Please type over the code in the Anti-Bot CAPTCHA image to the inputfield.";
  47. }
  48. ElseIf ($domapi == -2) { //invalid CAPTCHA
  49. $domain_error = "You haven't typed over the Anti-Bot CAPTCHA code correcly, please try again.";
  50. }
  51. ElseIf ($domapi == -3) { //invalid or empty domain given
  52. $domain_error = "Please enter a valid domain.";
  53. }
  54. ElseIf ($domapi == -4) { //domain is unavailable for registration
  55. $domain_error = "This domain is unavailable for registration, please choose an other domain.";
  56. }
  57. ElseIf ($domapi == -5) { //invalid URL
  58. $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.";
  59. }
  60. ElseIf ($domapi == -6) { //invalid e-mail address
  61. $domain_error = "Please fill in a valid e-mail address. You need it to activate your domain.";
  62. }
  63. ElseIf ($domapi == -7) { //invalid category
  64. $domain_error = "Please choose a valid category for your domain.";
  65. }
  66. ElseIf ($domapi == -8) { //invalid title
  67. $domain_error = "You have entered an invalid title. It must have more then 2 and less then 100 characters.";
  68. }
  69. ElseIf ($domapi == -9) { //invalid description
  70. $domain_error = "You have entered an invalid description. It may not have more then 150 characters.";
  71. }
  72. ElseIf ($domapi == -10) { //invalid keywords
  73. $domain_error = "You have entered invalid keywords. You may not enter more then 380 characters.";
  74. }
  75. ElseIf ($domapi == -11) { //invalid favicon
  76. $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.";
  77. }
  78. ElseIf ($domapi == -12) { //invalid language
  79. $domain_error = "You have entered an invalid language. It may not contain more then 50 characters.";
  80. }
  81. ElseIf ($domapi == -13) { //invalid revisit
  82. $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).";
  83. }
  84. ElseIf ($domapi == -14) { //invalid robots
  85. $domain_error = "You have entered an invalid robots value. It may not have more then 50 characters.";
  86. }
  87. Else { //this should not happen - maybe your server is running PHP on safe mode (or file_get_contents is otherwise disabled)?
  88. $domain_error = "An unknown error has occured, please try again later.";
  89. }
  90. }
  91. ?>
  92. <h2>nl.ae domain registration example script</h2>
  93. <?php If ($_SESSION['phase'] == 1) { //if phase 1 show domain whois form ?>
  94. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  95. <?php
  96. If((isset($send)) AND ($send == 1)) {
  97. If(isset($domain_error)) {
  98. echo "<p style='color: red;'>".$domain_error."</p>";
  99. }
  100. }
  101. ?>
  102. <p>www.<input type="text" maxlength="50" size="20" id="domain" name="domain" value="domain" />.nl.ae</p>
  103. <input class="button" type="submit" value="check!" />
  104. </form>
  105. <?php } ElseIf ($_SESSION['phase'] == 2) { //if phase 2 show domain information input form
  106. $_SESSION['apiid'] = file_get_contents("http://nl.ae/domainapi/reqid.php"); //identify with nl.ae server, used for CAPTCHA below ?>
  107. <p>Congratulations, this domain is still available for registration. Please fill in the details below.</p>
  108.  
  109. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  110. <?php
  111. If((isset($send)) AND ($send == 1)) {
  112. If(isset($domain_error)) {
  113. echo "<p style='color: red;'>".$domain_error."</p>";
  114. }
  115. }
  116. ?>
  117. <p><b>Required Fields (these must be filled in)</b><br />
  118. Domain: www.<?php echo $_SESSION['domain']; ?>.nl.ae<br />
  119. Redirect URL: <input type="text" id="url" name="url" value="<?php if (isset($_SESSION['url'])) { echo $_SESSION['url']; } else { echo "http://"; } ?>" /><br />
  120. 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 />
  121. Category: <select id="category" name="category">
  122. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "none")) { echo 'selected="selected"'; } ?> value="none">Choose --></option>
  123. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "blogs")) { echo 'selected="selected"'; } ?> value="blogs">Blogs</option>
  124. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "business")) { echo 'selected="selected"'; } ?> value="business">Business</option>
  125. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "computers")) { echo 'selected="selected"'; } ?> value="computers">Computers and Internet</option>
  126. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "education")) { echo 'selected="selected"'; } ?> value="education">Education</option>
  127. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "entertainement")) { echo 'selected="selected"'; } ?> value="entertainement">Entertainement</option>
  128. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "games")) { echo 'selected="selected"'; } ?> value="games">Games</option>
  129. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "health")) { echo 'selected="selected"'; } ?> value="health">Health</option>
  130. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "literature")) { echo 'selected="selected"'; } ?> value="literature">Literature and Culture</option>
  131. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "miscelaneous")) { echo 'selected="selected"'; } ?> value="miscelaneous">Miscelaneous</option>
  132. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "multimedia")) { echo 'selected="selected"'; } ?> value="multimedia">Multimedia</option>
  133. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "religion")) { echo 'selected="selected"'; } ?> value="religion">Religion</option>
  134. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "science")) { echo 'selected="selected"'; } ?> value="science">Science</option>
  135. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "society")) { echo 'selected="selected"'; } ?> value="society">Society</option>
  136. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "sport")) { echo 'selected="selected"'; } ?> value="sport">Sport</option>
  137. <option <?php if ((isset($_SESSION['category'])) AND ($_SESSION['category'] == "teen")) { echo 'selected="selected"'; } ?> value="teen">Teen</option>
  138. </select><br /></p>
  139.  
  140. <p><b>Optional Fields (these can be left empty)</b><br />
  141. 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 />
  142. Description: <input type="text" id="description" name="description" value="<?php if (isset($_SESSION['description'])) { echo $_SESSION['description']; } ?>" /><br />
  143. Keywords: <input type="text" id="keywords" name="keywords" value="<?php if (isset($_SESSION['keywords'])) { echo $_SESSION['keywords']; } ?>" /><br />
  144. 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 />
  145. Language: <input type="text" id="language" name="language" value="<?php if (isset($_SESSION['language'])) { echo $_SESSION['language']; } ?>" /><br />
  146. Revisit: <input type="text" id="revisit" name="revisit" value="<?php if (isset($_SESSION['revisit'])) { echo $_SESSION['revisit']; } else { echo 0; } ?>" /> days<br />
  147. Robots: <input type="text" id="robots" name="robots" value="<?php if (isset($_SESSION['robots'])) { echo $_SESSION['robots']; } else { echo "index, follow"; } ?>" /></p>
  148.  
  149. <p><b>Anti-Bot Verification</b><br />
  150. Please copy the code shown in the image to the inputfield below.<br />
  151. <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 />
  152. <input type="text" id="captcha" name="captcha" value="" />
  153. </p>
  154.  
  155. <input class="button" type="submit" value="register domain!" />
  156. </form>
  157. <?php } ElseIf ($_SESSION['phase'] == 3) { //if phase 3 show confirmation page
  158. $_SESSION['phase'] = 1; //reset phase to 1 so user can register a new domain on refresh ?>
  159. <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>
  160. <?php } ?>

Download code! Download code (.txt)

Download dit script! Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (2)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.055s