Web and Database Development Environment PHP Example

Please go through the HTML Example before doing this example.

Create a sample php file

  1. Go to the examples sub-directory of your web development directory and list the contents of the directory that end in .php:

    [username@l-lnx101 username]$ cd /webdev/user/username/examples
    [username@l-lnx101 examples]$ ls *.php
    sample_mysql.php  sample_psql.php

  2. There are two scripts which are example of using php to connect to a mysql database and a postgresql database. You can edit/view them with nano by typing nano sample_mysql.php or nano sample_psql.php.
  3. Using nano, we can create tutorial.php:

    [username@l-lnx101 examples]$ nano tutorial.php

  4. Copy and paste the following code into your nano screen:

    print "REMOTE_ADDR is $ip";
    $userhost= gethostbyaddr($_SERVER["REMOTE_ADDR"]);
    print "<br>\n";
    print "Lookup of $ip is <strong>$userhost</strong>\n";

  5. Save the file and go to http://webdev.cs.uiowa.edu/~username/examples/tutorial.php where username is replaced with your divmsid.
  6. The page when viewed on l-lnx100 in the lab looks like:

    Lookup of is l-lnx100.divms.uiowa.edu