Short Tag – Web Development Blog

Entries for July, 2010

Get the values of PHP directives

echo ini_get("post_max_size");

This is the way you get the values of a PHP directive. It is a very handy function.
It can be used to:
* check if register globals is active on server or not: ini_get(“register_globals”)
* check what is the max upload and post size at upload: ini_get(“post_max_size”), ini_get(“upload_max_filesize”)
* check what is the max execution time for [...]

Connect to multiple Mysql databases with PHP

Sometimes we need to connect to multiple databases with our PHP script. Try not to connect to too many different hosts, this can increase considerably the execution time of your script.
First, I create the 2 connection with 2 hosts:

$user1 = "";
$pass1 = "";
$db1 = "";
$host1= "";
$conn1 = mysql_connect($host1, $user1, $pass1);

$user2 = "";
$pass2 = "";
$db2 [...]

Post to twitter with PHP, twitting with PHP

I wrote a post about using file_get_contents() in PHP with context stream a while ago. I thought I’d post a usage example. Below is a function that posts your message into your twitter profile directly from PHP.

function myTweet($username, $password, $msg)
{
$context = stream_context_create(array(
‘http’ => array(
‘method’  => ‘POST’,
‘header’  => sprintf("Authorization: Basic %s\r\n", base64_encode($username.’:’.$password)).
"Content-type: [...]

Cancel action on a link (do not reload the window on click)

When you are developing using javascript it is often you get to the situation where you want to do something with javascript when the user clicks on the link. The problem is that when the user clicks on the link the browser will reload the window (and you don’t want that).
1.) Disable reload using HTML

<a [...]

Multidimensional arrays in Smarty, List menus

If you are working with template engines in PHP you probably heard of Smarty.
Official website: http://www.smarty.net
There is a situation that is not well documented on their site, so I thought I will explain it in my blog. As the title says, I am going to talk about listing multidimensional arrays in smarty. Let’s say you [...]