PHP
  Home arrow PHP arrow PHP Networking
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP Networking
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-09-08

    Table of Contents:
  • PHP Networking
  • DNS and PHP
  • DNS and PHP continued
  • Getting information about a domain name

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP Networking


    (Page 1 of 4 )

    PHP has a great many tools for interacting with a network and also with the Internet. In this article we will look at some of those tools and functions to see how we can use them to make our scripts more useful in a network environment. This article is the first of two parts.

    Accessing other websites

    Accessing other sites with PHP is extremely easy. But why would you want to access another website? If you just want to get information from a website, for instance a website that has a weather report on a city that is of interest to you, then you can write a spider and get that information and more. I said accessing websites with PHP is easy because you access a website in pretty much the same way that you would access a text file on your hard drive, i.e. by using fopen().


    fopen(http://localhost/websecure/ftp.php, “r”);


    The fopen() function that we use to open files is also used to open web pages, because a web page is essentially a file on a server. fopen() has the following modes:



    Mode

    Meaning

    r

    Reading only, begins reading at the start of the file.

    r+

    Reading or writing, begins reading at the start of the file.

    w

    Writing only. Creates the file if it does not exist, and overwrites any existing content.

    w+

    Reading or writing. Creates the file if it does not exist, and overwrites any existing content (when writing).

    a

    Writing only. Creates the file if it does not exist, and appends the new data to the end of the file.

    a+

    Reading or writing. Creates the file if it does not exist, and overwrites any existing contents (when writing).

    x

    Writing only. Creates the file if it does not exist, but does nothing, issues a warning, if the file does exist.

    x+

    Reading or Writing. Creates the file if it does not exist, but do nothing, issues a warning, if the file does exist.

    You will only be able to open a file for reading, unless the permissions are set otherwise. Also you will have to use a trailing slash after a directory because fopen does not support redirects. For example:


    fopen(“http://localhost/websecure/ftp.php/”, “r”);


    the above example is fine, but the one below will fail:


    fopen(http://localhost/websecure/ftp.php, “r”);


    Once you’ve opened a file, you can pretty much treat it the same way you would any other file, using common functions such as file() or fgets() to place or retrieve the data.

    An example in code might be something like this:


    <!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=iso-8859-1" />

    <title>Untitled Document</title>

    </head>


    <body>

    <form action="tester.php" method="get">

    <input name="url" type="text" />

    <input name="" type="button" />

    </form>

    </body>

    </html>


    And the processing code might look something like this:


    <?

    $url=$_POST['url'];

    $fp=file($url);

    $n=count($fp);

    $r=rand(0,($n-1));

    echo trim($fp[$r]);

    echo $n;

    ?>


    More PHP Articles
    More By David Web


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT