Archive for the 'PHP' Category

Install GD support php5-gd in Ubuntu

Written by coregps on Monday, July 23rd, 2007 in PHP, Ubuntu.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

I have installed a support ticket system with captcha enabled and everything works well except the images does not display.

It seems that the does not configured with by default. However comes with package called . Just type following command to install this module:

$ sudo apt-get install php5-gd

And then restart Apache

$ sudo /etc/init.d/apache2 restart

Installing OTRS on Ubuntu

Written by coregps on Saturday, July 21st, 2007 in General, Linux, Open Source, PHP.

is an open-source Issue tracking system software package which a company, organisation or institution can use to assign tickets to incoming queries, thereby greatly facilitating the handling of support requests and other customer traffic. The most exciting is it is already contained in the package repositories. Installing OTRS is easy as 1-2-3!

1. Install OTRS package and dependencies:

$sudo apt-get install otrs

2. Copy the file /etc/otrs/apache2-httpd.include.conf to /etc/apache2/conf.d.

3. Restart Apache service:

$sudo /etc/init.d/apache2 force-reload

4. Use the following address to access the web installer, then follow the steps and setup the system.

http://localhost/otrs/installer.pl

5. Restart Apache again:

$sudo /etc/init.d/apache2 force-reload

That’s all. Now, you can visit admin interface at http://localhost/otrs/index.pl, and customer interface at http://localhost/otrs/customer.pl.

PHP function used to check if a URL exists

Written by coregps on Monday, December 25th, 2006 in PHP.

I have a PHP function which is used to check if a URL exists. It works very well on my old web server. However, when I switched to my new hosting providers, It can’t work any more. The code of the function is as following:

< ?php
function check_url($url)
{
$furl = @fopen($url, "r");
if (!$furl) {
return false;
}
@fclose($furl);
return true;
}
?>

Aftering the PHP manual, I found the following section:

If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.

When I looked at the phpinfo() page. I found that the parameter “allow_url_fopen” was set to “Off”. Although someone recommend setting this parameter to On using ini_set at the first line of the script:

< ?php

ini_set("allow_url_fopen", "1");
?>

This made no difference. In the PHP manual, I found the root cause of the problem.

allow_url_fopen boolean
This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of remote files using the ftp or http protocol, some extensions like zlib may register additional wrappers.
Note: This setting can only be set in php.ini due to security reasons.
Note: This option was introduced immediately after the release of version 4.0.3. For versions up to and including 4.0.3 you can only disable this feature at compile time by using the configuration switch –disable-url-fopen-wrapper.

Finally, I implemented my function using CURL which can be used to connect and communicate to many different types of servers with many different types of protocols.

< ?php
function check_url($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops

curl_exec ($ch);

$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);

if ($code != 200 && $code != 302 && $code != 304) {
return false;
} else {
return true;
}
}
?>


Or

< ?php
function check_url($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops
$data = curl_exec($ch);
curl_close($ch);
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/", $data, $matches);
$code = end($matches[1]);
if (!$data) {
return 0; // "Domain could not be found";
} else {
if ($code == 200) {
return true; // "Page Found";
} elseif ($code == 404) {
return false; // "Page Not Found";
}
}
}
?>

And the following is the usage example:

< ?php
if (check_url("http://www.memezilla.com")) {
echo "URL is OK!";
} else {
echo "URL Error";
}
?>


Site Navigation