Tag: PHP

Download youtube video’s: build your own video grabber/downloader in php with curl

And again i searched the internet for some “easy” script to grab/download youtube movies to my own server.
I failed! So wrote my own.

Let me explain the steps or jump over to the VERY short working code:

First step we need to do 3 things:

*1: make a request to youtube for getting the required data
*2: make a second request to really get the .FLV file
*3: save the data to a file

*1: make a request to the url, in this case it is:

(just grabbed a url dont look at the content of it :) )
(continue reading…)


Kohana php framework auth module working example

*EDIT: check this post for an easy auth module i made myself

I searched the internet for a “GOOD” documentation about the auth module in kohana.
Couldnt find one… (not even on the official website….). [official documentation]
The example they include in the download of kohana isnt working at all (misses classes and so on….)

So i made an simple example.

Let’s start:

I assume that u have the auth tables allready correct inserted into youre database.
(if not go to modules/auth/views/auth/install.php query should be in the php source…)

Create a file login_test.php
place it in: application/controllers

CTR-C and CTRL-V the code in that file.
Goto: youredomain.nl/login_test
(continue reading…)


PHP5 and objects

When you cloned an object in PHP 4 and changed one of the variables, this was only changed in the copy. You would have to explicitly tell PHP to make a reference by using the & sign.

In PHP 5 this was changed. When you do anything with an object it is always a reference. You can however change this by using the lesser known clone construct.

Take for example the following situation:

<?php
class Console
{
	public $hello;
}

$console = new Console();
$console->hello = 'world';

$clone = $console;
$clone->hello = 'clone';

echo '$console: ' . $console->hello;
echo '$clone: ' . $clone->hello;
?>

In PHP 4 this would output

$console: world
$clone: clone

However in PHP 5 this will output

$console: clone
$clone: clone

To create a real clone of the Console class you can use the clone construct like this:

<?php
$console = new Console();
$console->hello = 'world';

$clone = clone $console;
$clone->hello = 'clone';

When you see the output now, it’s actually what you’d expect it to be:

$console: world
$clone: clone

Plesk and PHP’s open_basedir restriction

When you get a fatal error from PHP which is saying that the open_basedir restrictions are in place it simply means that it’s not possible to include or open files outside these directories.

However, this can be solved by changing the ‘open_basedir‘ ini using the ini_set() function or when you’re hosted on a Plesk server by creating a vhost.conf file in the conf directory using the following contents:

<Directory VHOST_DIR/httpdocs>
php_admin_value open_basedir "VHOST_DIR/httpdocs:/tmp:VHOST_DIR/ADD_DIR"
</Directory>

Change VHOST_DIR to the directory of your domain, and ADD_DIR to the directory you wish to add. After this run the following command to reload the configuration for the webserver.

/usr/local/psa/admin/sbin/websrvmng -v -a

However, chances are that this is not possible for your account at which point you have to ask your hoster to either disable or add the directory the open_basedir directive for your account.


Getting started with the Zend Framework

I’ve started playing with the Zend Framework and noticed that there were lots of getting started tutorials for the old versions. Since many of them don’t update or work anymore I’ve decided to write my own getting started version which should get you up to speed with Zend Framework version 1.0.1 in no time.

At first you need to download and install the framework in a seperate directory, you can either choose that it’s available in the include_path using the php.ini file or by setting it up in a folder which will be used only for your application. If you go for the first one edit the php.ini and search for the include_path directive, add the complete path to the library directory from the extracted Zend Framework archive and you should be set, don’t forget to reload Apache!

The second method is slightly harder but it should also be possible when you’re on a shared hosting platform and the provider hasn’t got the framework installed. Extract the archive somewhere outside the web root (this means that it shouldn’t be accessible through the website).

When you set up a new project, the following directory structure is recommended:

- app
    - controllers
    - views
        - scripts
- library (contains the Zend Framework files)
- public_html (or htdocs in other cases - this is the web root)

In the public_html directory create a file called index.php. This will be our bootstrap for the framework. But first we need to get the PHP error reporting to a decent level and make sure to have access to the framework files. Open index.php and add the following; (continue reading…)


Enabling SSL support in cURL

In some occasions the cURL package may be installed but PHP still reports an error saying something that cURL is installed but without SSL support compiled into it. If your server has OpenSSL installed (look for it by issuing the whereis openssl command) you should download and/or recompile the libcurl package with the following commands;

./configure --with-ssl
make
make install

You probably need to be root when doing the last command (make install).

Now, when you restart Apache, PHP should be able to use SSL connections to other sites without any problems!


Copyright © 1996-2010 Re:morse.nl. All rights reserved.
iDream theme by Templates Next | Powered by WordPress