User Tools

Site Tools


courses:2009.05.11.web.programming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:2009.05.11.web.programming [2009/05/11 01:10]
camille added geolocation
courses:2009.05.11.web.programming [2009/05/11 01:13] (current)
camille added image
Line 1: Line 1:
 +====== may 11: Web Programming,​ part 2 ======
  
 +==== HTML + PHP ====
 +  * How to gather from the page/user? URL parameters, forms, etc.
 +  * A basic form
 +  * <code html>
 +<<​!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>​
 +
 +</​code>​
 +  * {{:​courses:​html_simple_form.jpg|}}
 +  * Access the submitted data
 +  * <code php>
 +<?php
 +// check if we have incoming data/​variable
 +$usernameValue = $_REQUEST['​username'​];​
 +
 +// output data
 +echo '<​p>​username:​ '​.$usernameValue.'</​p>';​
 +?>
 +</​code>​
 +  * $_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 [[http://​reference.sitepoint.com/​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 [[http://​en.wikipedia.org/​wiki/​Geolocation|wikiepedia]]
 +  * From a web visitor to a geolocation. We can use some PHP libraries for doing that. [[http://​www.maxmind.com/​app/​ip-location|MaxMind.com]] or others
 +  * Already installed on the server. Here is how to use it
 +  * <code php>
 +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
 +}
 +</​code>​
 +  * Showing geolocation on Google Maps. Requires javascript and [[http://​code.google.com/​apis/​maps/​| Google Maps API]]
courses/2009.05.11.web.programming.txt · Last modified: 2009/05/11 01:13 by camille