Why So Scared

A blog about; Programming, Music and Random Stuff

Making Leopard 10.5 PHP Ready

I’m a Ruby on Rails ‘man’, but recently thanks to Warez-DnB I’ve increasingly been exposed to PHP. To make the built in Apache server on Leopard 10.5 PHP Ready follow these simple steps

  1. Edit the httpd.conf file, at /private/etc/apache2/httpd.conf
  2. Edit the file (you can use Pico “sudo pico httpd.conf”) and search for LoadModule php5_module
  3. Uncomment the line that says #LoadModule php5_module (Delete the #)
  4. Save
  5. Stop and start the web server in the control panel
Tags: ,
posted by Juo in Apple, tidbit and have Comment (1)

Forbidden 403 error in Leopard 10.5

When turning on web sharing on 10.5 I had an error message

Forbidden: 403 Error
You dont have permissions to access localhost/~juo

Strange I thought, the fix is pretty simple though.

  1. Edit the httpd.conf file, at /private/etc/apache2/httpd.conf
  2. Edit the file (you can use Pico “sudo pico httpd.conf”) and search for <Directory />
  3. Change the line that says Deny from all to Allow from all
  4. Save
  5. Stop and start the web server in the control panel
posted by Juo in Apple, Random, tidbit and have No Comments

Batch Rename Suffixes or Prefixes Terminal

Someone on a forum I regular asked how to batch rename suffixes within the terminal.

So The filenames;
filename.rar
filename2.rar
filename3.rar

Could have a suffix added like this;
filename_[sitename].rar
filename2_[sitename].rar
filename3_[sitename].rar

Suffix

for i in *.rar; do mv “$i” “`basename $i .rar`_[sitename].rar”; done

Prefix

find *.rar -exec mv {} [sitename]_{} \;

posted by Juo in tidbit and have No Comments

PHP function check if a file (or url exists)

While doing some scripting for Warez-DnB (for a new feature that ill talk more about soon) I needed a script that would check if a file on the server existed.

The PHP code below does this job perfectly, returning a boolean TRUE if the file is found and FALSE if it isn’t .

function url_exists($url) {
// Version 4.x supported
$handle   = curl_init($url);
if (false === $handle)
{
return false;
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
curl_setopt($handle, CURLOPT_HTTPHEADER, Array(”User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15″) ); // request as if Firefox
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
}

function url_exists($url) {

// Version 4.x supported

$handle   = curl_init($url);

if (false === $handle)

{

return false;

}

curl_setopt($handle, CURLOPT_HEADER, false);

curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works

curl_setopt($handle, CURLOPT_HTTPHEADER, Array(”User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15″) ); // request as if Firefox

curl_setopt($handle, CURLOPT_NOBODY, true);

curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);

$connectable = curl_exec($handle);

curl_close($handle);

return $connectable;

}

I thought someone else might find it useful.

Tags: ,
posted by Juo in tidbit and have Comment (1)

PHP Image Watermarking

If you’ve ever wanted to watermark images on your website, this neat script will be just what you’re looking for.

Warez-DnB watermark

The Warez-DnB Watermark

The watermark image is held in a separate file, rather than having to actually edit each image with your watermark, save and upload, this script will serve the watermark to the user on the image as  and when its requested.

I like this approach to watermarking because no only is it much easier than editing each picture individually it also means with FTP access you still have an original image intact without the watermark. Only users connecting via HTTP will see the watermarked version.

This also allows for ultimate flexibility, if for whatever reason you decide to change the site logo, its as simple as replacing one image file and every image hosted will have the new watermark.

Read more…

Tags: ,
posted by Juo in tidbit and have Comments (2)