As discussed in the "Web Application Design" section of this tutorial, the PHP script should accomplish four unique functions aside from the normal functions of retrieving data from the POST array and doing a minor validation task. <?php } else {
//The web form has been submitted, grab the data from POST as well as remove the white space using trim command
$url =trim($_POST['url']);
//Check if the form submitted contains any data. //Also check if the security code is correct. //More information about captcha design here http://www.devshed.com/c/a/PHP/Designing-a-Captcha-System-with-PHP-and-MySQL/
if ((empty($url)) || (!(trim($_POST['captcha'])==$_SESSION['answer']))) {
//Feedback to the user that the form does not contain any data
die ('ERROR: Enter figures or correct captcha. <a href="/descriptivestats.php">Click here to proceed with the analysis</a>');
} else {
//The data from the $url comes from an array (POST), //You need to explode the data from the array using PHP explode function //And then assigned the data to a $data variable //This will do the job of actually parsing the URL from the web form
$data = explode("n", $url);
//Display to the web browser the heading sections of the XML syntax using Google XML sitemap standard
echo '<font face="Courier New" size="2">'; echo '<font color="#C0547F"><i><?xml version="1.0" encoding="UTF-8"?></i></font>'; echo '<br />'; echo '<font color="#7C137F"><b><urlset</b></font> <b>xmlns</b>=<font color="blue">"http://www.sitemaps.org/schemas/sitemap/ echo '<br /><br />';
//The code below computes the priority of the URLs in sitemap. //The most important URL (the one entered first by the user in the web form has a priority of 1.) //The minimum or lowest assigned priority is 0.5 regardless of how many URLs are being processed. //To compute the decrement value or how much is the priority differences between the highest priority of 1 to the lowest assigned priority of 0.5 are to use the formula: // (0.5)/ ((Number of URLs)-1) //In PHP, it needs to use the sizeof function to count the number of URLs in the data variable.
$difference = (-0.5)/((sizeof($data))-1);
//The following below is a WHILE Loop which will do the actual tasks of generating the XML syntax for all the URLs
$priority=1.0; while (($priority>=0.4) && (list($key,$value) = each($data))) { $roundpriority=round($priority,2); echo "<font color='#7C137F'><b><url</b></font>>"; echo "<br />"; echo " <<font color='#7C137F'><b>loc</b></font>>$value</<font color='#7C137F'><b>loc</b></font>>"; echo "<br />"; echo " <<font color='#7C137F'><b>priority</b></font>>$roundpriority</<font color='#7C137F'><b>priority</b></font>>"; echo "<br />"; echo "</<font color='#7C137F'><b>url</b></font>>"; echo "<br /><br />";
//after each loop, the priority is decreased by a difference value computed earlier, the $difference variable is a negative number.
$priority=$priority+$difference; } echo "</<font color='#7C137F'><b>urlset</b></font>>"; } } ?>
<!--Clears out the session variable-->
<?php $_SESSION = array (); session_destroy (); ?> </body> </html>
blog comments powered by Disqus |
|
|
|
|
|
|
|