Web hosting reviews - USING PHP TO MANAGE FILES pass the URL

USING PHP TO MANAGE FILES pass the URL as an argument to the function. Unfortunately, as noted earlier, many hosting companies disable the allow_url_fopen setting in PHP. One way to get around this is to use a socket connection instead. To create a socket connection, use the fsockopen() function, which takes the following five arguments: The target domain name The port you want to open for web pages, this is always 80 A variable to capture an error number if the connection fails A variable to capture any error message The number of seconds to attempt the connection before timing out Only the first argument is required, but using all five is a good idea since you can always use the same values, and the error message may help you understand what s gone wrong if the connection fails. The fsockopen() function works in a very similar way to fopen() by opening a file for you to read. Let s use fsockopen() to access the friends of ED news feed at www.friendsofed.com/ news.php. PHP Solution 7-5: Opening a news feed with fsockopen() 1. Create a PHP file called fsockopen.php in the filesystem folder. If you just want to study the final code, use fsockopen.php in the download files for this chapter. 2. If your script editor automatically inserts a DOCTYPE declaration and XHTML skeleton, remove them. You need to start with a blank page. Insert the following code: This is the basic skeleton for any socket connection using fsockopen(). The only change you normally need to make is to the first argument, which is the domain name of the site that you want to access. If a connection can t be made, the first half of the conditional statement displays the error message and number. If the error number is 0, it may indicate the socket connections have been disabled on your server. In that event, consult your hosting company. If a successful connection is made, the else clause is executed. At the moment, it contains just a comment. So let s fix that now. 203
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Leave a Reply