home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 April / Chip_2003-04_cd1.bin / zkuste / phpgtk / download / samples / ip.php < prev    next >
PHP Script  |  2002-08-06  |  3KB  |  95 lines

  1. <?php
  2.     /*
  3.     * ip_lookup.php - My first attempt at PHP-GTK.
  4.     *
  5.     * Author: Josh Sherman
  6.     * Purpose: Looks up the IP address for a domain.
  7.     * Usage: php -q ip_lookup.php
  8.     *
  9.     */
  10.     // Check to see if the PHP-GTK extension
  11.     //     is available.
  12.     if (!class_exists('gtk')) {
  13.         if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
  14.             dl('php_gtk.dll');
  15.         else
  16.             dl('php_gtk.so');
  17.     }
  18.     // Called when delete-event takes place,
  19.     //     tells it to proceed.
  20.     function delete_event()
  21.     {
  22.         return false;
  23.     }
  24.     // Called when the window is being destr
  25.     //     oyed, tells it to quit the main loop.
  26.     function destroy()
  27.     {
  28.         Gtk::main_quit();
  29.     }
  30.     // Called when the button is clicked, lo
  31.     //     oks up the IP and places it in the
  32.     // entry box.
  33.     function get_ip()
  34.     {
  35.         global     $text;
  36.         global    $domain;
  37.         global    $window;
  38.         global    $ip_address;
  39.         $domain = $text->get_text();
  40.         $ip_address = gethostbyname($domain);
  41.         $text->set_text($ip_address);
  42.     }
  43.     // Creates a new top-level window and co
  44.     //     nnect the signals to the appropriate
  45.     // functions.
  46.     $window = &new GtkWindow();
  47.     $window->connect('destroy', 'destroy');
  48.     $window->connect('delete-event', 'delete_event');
  49.     $window->set_border_width(5);
  50.     $window->set_title('IP Look-up');
  51.     $window->set_policy(false, false, false);
  52.     // Creates a table to place the widgets
  53.     //     in, and adds it to the window.
  54.     $grid = &new GtkTable(2, 2);
  55.     $grid->set_row_spacings(4);
  56.     $grid->set_col_spacings(4);
  57.     $window->add($grid);
  58.     // Creates a label to describe the entry
  59.     //     field and adds it to the table.
  60.     $label = &new GtkLabel();
  61.     $label->set_text("Domain:");
  62.     $grid->attach($label, 0, 1, 0, 1);
  63.     // Creates an entry field and adds it to
  64.     //     the table.
  65.     $text = &new GtkEntry();
  66.     $text->set_editable(true);
  67.     $text->set_max_length(256);
  68.     $grid->attach($text, 1, 2, 0, 1);
  69.     // Creates tooltips object for the entry
  70.     //     field.
  71.     $ttentry = &new GtkTooltips();
  72.     $ttentry->set_delay(200);
  73.     $ttentry->set_tip($text, 'Type the domain you want to look up here.', '');
  74.     $ttentry->enable();
  75.     // Creates a button, connects its clicke
  76.     //     d signal to the get_ip() function and
  77.     // adds the button to the window.
  78.     $button = &new GtkButton('Get IP');
  79.     $button->connect('clicked', 'get_ip');
  80.     $grid->attach($button, 0, 2, 1, 2);
  81.     // Creates tooltips object for the butto
  82.     //     n.
  83.     $ttbutton = &new GtkTooltips();
  84.     $ttbutton->set_delay(200);
  85.     $ttbutton->set_tip($button, 'Looks up the IP', '');
  86.     $ttbutton->enable();
  87.     // Show the window and all of it's child
  88.     //     widgets.
  89.     $window->show_all();
  90.     // Set focus to the entry field.
  91.     $window->set_focus($text);
  92.     // Run the main loop.
  93.     Gtk::main();
  94.     ?>
  95.