User Tools

Site Tools


courses:2009.05.11.web.programming

may 11: Web Programming, part 2

HTML + PHP

  • How to gather from the page/user? URL parameters, forms, etc.
  • A basic form
  • <<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>simple form</title>
    </head>
     
    <body>
    <h1>A simple form</h1>
    <form id="form1" name="form1" method="post" action="simpleform.php">
    <p>username <input name="username" type="text" /></p>
    <p>active <input name="active" type="checkbox" value="" /></p>
    <p><input type="submit" value="submit" /></p>
    </form>
    </body>
    </html>
  • Access the submitted data
  • <?php
    // check if we have incoming data/variable
    $usernameValue = $_REQUEST['username'];
     
    // output data
    echo '<p>username: '.$usernameValue.'</p>';
    ?>
  • $_REQUEST, $_GET, $_POST
  • Never trust user-submitted data directly. Assume it is malicious. Always validate.
  • Other form elements: radio, file, checkbox, image button, etc.
  • Good reference for web/html Sitepoint.com

Geolocation

  • Geolocation is the identification of the real-world geographic location of an Internet-connected computer, mobile device, website visitor or other. Source wikiepedia
  • From a web visitor to a geolocation. We can use some PHP libraries for doing that. MaxMind.com or others
  • Already installed on the server. Here is how to use it
  • require_once "Net/GeoIP.php";
     
    $geoip = Net_GeoIP::getInstance("/home/56771/domains/interactiondesign.se/GeoLiteCity.dat");
     
    try {
    	$location = $geoip->lookupLocation($_SERVER['REMOTE_ADDR']);
     
    	echo "City: ".$location->city."<br>";
    	echo "Latitude: ".$location->latitude."<br>";
    	echo "Longitude: ".$location->longitude."<br>";
     
    } catch (Exception $e) {
    	// Handle exception
    }
  • Showing geolocation on Google Maps. Requires javascript and Google Maps API
courses/2009.05.11.web.programming.txt · Last modified: 2009/05/11 01:13 by camille