Browsing Category: "PHP"

Yahoo comment submission bug

PHP May 14th, 2008

I was reading a article about a Iphone Killer, a new phone called Diamond and started to read some comments about the article.

At the end of the first page I have saw that if I wanned to post a comment I should sign in, so I did go forward to read more, but when I got back to the first page, guess what, the comments form was wide open.

yahoobug2.jpg

yahoobug1.jpg

I tried for a while and looked like that the bug was sporadicly, but every time that I have clicked on the first page and on the last it did happens.

Check it out…

Here’s the link of the article: http://tech.yahoo.com/blogs/patterson/18364?comment_start=166&comment_count=20#see_comments

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Best Practices for Speeding Up Your Web Site

PHP May 5th, 2008

Best Practices for Speeding Up Your Web Site

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

PHP Manual

PHP May 5th, 2008

Writing a manual for a user is not the most fun of the tasks, but is necessary.

If you search on Google for a PHP user help tool, you are going to find a bunch of links tools that can easily create glossaries and manuals for developers, such as PHPDoc, but hardly enough you are going to find a tool to create a manual of the system for a user.

After a lot of searching we have found one that is very simple: http://www.kubelabs.com/phpmanualcreator.php

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Enabling htaccess and mod_rewrite on OS X

PHP April 23rd, 2008

Enabling .htaccess on OS X isn’t a very easy task. In order to that to work you will need, besides the loadmodule mod_rewrite.so and addmodule mod_rewrite.c, to change the httpd.conf and the website conf file. If you change only the httpd.conf it wont work and if you change only the site.conf it would not work.

You can definitely get more details on: http://www.clagnut.com/blog/350/

He says to use Override All on httpd.conf and Override AuthConfig on the other, but in our case we used All on both (with some limitations of who can create the .htaccess files).

Anyway the article is very well explained and was very helpful with our little battle at our OS X server.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Vcard simple parser class

Web Development, PHP April 4th, 2008

This Vcard class is very simple and will parser one Vcard file with one contact at time and it works for Vcard versions 2 and 3.

It will basically get a Vcard file (or text file with Vcard formating) and parse through it returning an array with the following:

Array
(
[name] => Array
(
[lastname] => Robot
[firstname] => Tired
[middlename] =>
)
[fullname] => Tired Robot
[business] => Tired Robot Blog
[title] => Blog Picture
[note] => Any notes associated with this contact
[phone] => 5615615561
[home] => 5615615562
[cell] => 5615615563
[fax] => 5615615564
[address] => Array
(
[0] => 1234 NW Street with no Name St
[1] => Deerfield Beach
[2] => FL
[3] => 33442
[4] => United States
)

[url] => www.tiredrobot.com
[email] => info@tirerobot.com
);

The result of the parse is returned as an array to make it easier to adapt to other entities (objects) that you might be working with in a very generic way.

The class is constructed in PHP5 format.

Click here to download

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Coding Horror: Revisiting The Facts and Fallacies of Software Engineering

PHP March 26th, 2008

Coding Horror: Revisiting The Facts and Fallacies of Software Engineering

Some interesting lines:

  • The best programmers are up to 28 times better than the worst programmers. (how is that number calculated?)
  • Adding people to a late project makes it later.
  • The answer to a feasability study is almost always “yes”.
  • Modification of reused code is particularly error-prone.
  • Errors tend to cluster.
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Client-Side JavaScript Reference

PHP March 20th, 2008

Client-Side JavaScript Reference
This book is a reference manual for the JavaScript language, including both core and client-side JavaScript for version 1.3. JavaScript is Netscape’s cross-platform, object-based scripting language for client and server applications.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Looping into arrays

optimization, Web Development, PHP March 19th, 2008

There are some sites that try to do a benchmark over FOREACH and the FOR statement and not always they give a good position about it.

To understand which one will be the faster one, is simple:

FOREACH will automatically points the array pointer to the beginning of the array and will create a copy of the array to perform the loop and will increment the pointer in one always. FOR does not, but the FOR statement will check the 3 conditions that you have used on it.

Looping into arrays you have 3 conditions with the FOR statement.

- Where the pointer starts.
- Until when you want to perform the loop.
- and how the pointer will be incremented.

Considering that you have 3 scalar conditions, the FOR statement will be much faster than the FOREACH statement.

Ex.

$array = explode(’ ‘,’ Consider the following examples. All of them display the numbers 1 through 10:’);

foreach($array as $key => $value) {
if($key > 0) {
echo ‘ ‘;

}
echo $value;

}

$size = sizeof($array);
for($key = 0; $key < $size; ++$key) {
if($key > 0) {
echo ‘ ‘;
}
echo $array[$key];
}

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Pre-increment Array For Loops For Speed

PHP March 17th, 2008

fryewiles.PNGI’m familiar with the benefits of removing the array length calculation from your loop by pre-calculating the array length. I’m also familiar the benefits of using indexed arrays instead of associative arrays.

However, I didn’t know that using pre-increment rather than post in your counter calculation is faster.

From blog:

“Furthermore, if we switch from the post-increment operator, to the pre-increment operator, we should also see some time improvements. The difference is that in using the post-increment operator (a++), a copy of the variable is made, the original value is incremented, and then that copy is returned. With pre-increment operator (++a), the value is incremented and then returned, cutting the process down one less step. “

http://tinyurl.com/2rsrp2

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Creating a MySQL Dump with PHP Part I

PHP March 11th, 2008

There are 2 ways to do a MySQL dump with PHP.

- 1st. Use the mysqldump command to perform a full dump on the database and use PHP system() to execute the command. The problem with this is that not all servers are going to allow a script to perform a system call (for security reasons). The good part is that with not more than 5 lines of code you can generate a dump. You can get more info here.

- 2nd.  Use MySQL command queries to retrieve all tables from the database and retrieve the data inside each table. The only problem with this is that is loop intensive. The good part of this is being able to generate the dump in any server all you need is access to the server.

I have tried the first one and I could not generate any  dump because the server cannot use the PHP system() function to perform the mysqldump, so go to 2nd option and this is the option that I’m going to explain.

I’m going to divide this tutorial in 2 parts. The first one (this one) to explain all parts of the script and the second part (Part II) with the script.

The script is simple. You first need to retrieve the tables of the database to retrieve the data inside them.  You can use mysql_list_tables function, but is deprecated (not recommended to use), so use the following statement:

SHOW TABLES FROM `databasename`;

This is going to retrieve a list of all tables from the database and with this list we can retrieve the structure of each and the data.

Now the issue is going to be storing the information and avoiding the script die in timeout.

To store the information there are 2 ways: file and string. I have used both, so I can print on the screen and save the backup into a file.

I’m checking if the file already exists an in that case, writes on the end of the file, otherwise, creates a new one. This is important because when the script is checking for big tables, it is going to create them later and it’s going to append at the end of the file that was first created.

Now we got the tables and the files, so let’s retrieve the table structure. For that you just need to execute this statement:

SHOW CREATE TABLE `table_name`

This will output the whole create table script in the way that is needed to be for the selected table. Just a tip, always use the ` to wrap database and table names on these scripts, otherwise it will break in MySQL.

Now to create the insert statements, we need all the data and fields from the table. If you have created a export CSV script the concept will be the same.

You will need to:

1. Do a full SELECT on the table
2. Get the number of fields of the table. For this you can use msyql_num_fields($query).
3. Calculate how big the table is (only for performance).

With the SELECT you will retrieve the whole data. With the mysql_num_fields you will retrieve the number of fields of the table, so create the INSERT statement using both. This is the part that is extremely consuming.
Because of this part I’m checking before if the number of rows on the table is bigger than 20,000. In this case I’m saving this table name on a global array (session) and performing only that table latter on. This will avoid the script to die because a timeout.

Last part. Now you have all the tables that have not been processed, so do a loop on the array, and call the function (script before) on that table. It will save on the same file name and the SQL dump will be complete.

To preview if the database is too big you can use the “SHOW TABLE STATUS FROM `dbdatabase`”. This will return all tables and how many rows each table has as it data.

This was a big post, so just click here to get the script.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
blank