User Tools

Site Tools


may 11: Web Programming, part 2


  • How to gather from the page/user? URL parameters, forms, etc.
  • A basic form
  • <<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>simple form</title>
    <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>
  • 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


  • 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. 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/");
    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