Optimizing a php application in 5 minutes

by Tweak on November 24, 2010
in Php

It is often said that premature optimization is the root of all evil: it is indeed true that the optimization stage must come after the main development of an application has been completed. Optimizing means reducing loading and execution times, improving the user experience by making the application reacting more responsively.
When it comes the time to optimize your web application, don’t go blindly searching for the bottleneck. Often there are no obvious improvable points in a codebase and your assumptions about the slowness causes can be wrong. Profiling is the activity of discovering what is forcing your application run slower than expected, by analyzing the code execution and time tracking.
If your language of choice is php, fortunately this process takes only 5 minutes.
Read more…

Securing PHP webservers

by Tweak on October 29, 2010
in Php, Security

PHP applications have a reputation for higher than average security problems. What configuration techniques do you use for making sure the application is secure as possible ?

I’m looking for ideas like:

I normally use Linux, but feel free to suggest Windows solutions too.

By David Pashley?

Read more…

IP Address conversion in PHP

by Tweak on October 20, 2010
in Php

The purpose of this technote is to provide a small recipe for manipulating and/or converting IP addresses to decimals and back. I wrote a similar technote on how to do this in the Perl language. I thought it would be just as useful to know how to do the same thing in PHP. PHP has a few built-in functions but use of these functions may not yield the desired results.

The PHP function ip2long( string ip_address) is a built-in function that will return an integer. PHP’s Integer type is signed, so many IP addresses will result in a negetive number.
Read more…

Stop PHP nobody Spammers

by Tweak on June 25, 2009
in Php, Security, Servers

PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.

Watching your exim_mainlog doesn’t exactly help, you see th email going out but you can’t track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.

If you check out your PHP.ini file you’ll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP – so everything will go through /usr/sbin/sendmail =)

Requirements:
We assume you’re using Apache 1.3x, PHP and Exim. This may work on other systems but we’re only tested it on a Cpanel/WHM Red Hat Enterprise system. Read more…

Rotating Banner in PHP

by Tweak on June 17, 2009
in Php

This is a snippet that will rotate a banner on a page. All you have to do is set $File and $Images to the paths to the images. It will just do the next image in $Images in order. It doesn’t rotate banners for seperate users, it just goes through. Before you use it, create the $Stat file and set the contents of it to 0 and your ready to go!
Read more…

Text counter in PHP

by Tweak on June 17, 2009
in Php

A counter is an essential part of a site to know how many people are coming to site. Here is an easy way to make a counter. All you need is access to PHP and be able to chmod a directory. We’re going to save the amount of hits in a .dat file, so you don’t even need a mySQL database. First off, you have create a directory and CHMOD it 777 so PHP can write the counter.dat file.

Here is what we have to do:

  1. Use the file_exists() function in PHP and see if the counter.dat file exists. If it does, then open the file using the PHP fopen() function.
  2. Use the PHP fgets() function to find the number of hits there and save it in a variable.
  3. Add one to the variable.
  4. Close the file.
  5. Display the number of hits.
  6. Open the counter.dat file using the fopen() function and save it as a variable.
  7. Use the PHP fputs() function to insert the new number of hits.
  8. Close the file.
  9. If the counter.dat file doesn’t exist, then use the fopen() function and declare it as a variable.
  10. Use the Fputs() function and put a “1″ in there.
  11. Print out that 1 person has come to the page and then close the file.

Here is the code: Read more…

Create Random Text in PHP

by Tweak on June 16, 2009
in Php

Want to put a random quote on your site? Or randomize some other aspect of your site? It’s easy. You’ll want to use PHP or some other server-side scripting language instead of a client-side scripting language like JavaScript. Server-side languages write the content to the page in html before it ever leaves the server. Search engines will be able to read the content on your page, but with JavaScript they cannot, so you lose any content value of the random code. Also, if a user turns off JavaScript, that random content is lost. Google, MSN, and Yahoo will see that the content is changing often, and that may help your rankings (depending on your implementation).

Here’s how to put the random elements into your page, using PHP.

Step 1:
Create a text file called ‘myData.txt’. Open the file and put in your random elements, placing each random element on its own line, (whether text, images or html). Then place ‘myData.txt’ in the same directory as your page containing the PHP script.

Step 2:
Place the following PHP code into your page where you want the random element:
Read more…

How To Install IonCube Loader

by Tweak on June 14, 2009
in Php

If you need IonCube loader in order to encode scripts. You will need to install IonCube loadar on your box.

  1. Login to your server as root and download the loaderfor your server: http://www.ioncube.com/loader_download.php
  2. Then extract it
    tar -zxvf ioncube_loaders.tar.gz
    cd ioncube
  3. Copy ioncube-install-assistant.php file to a www diretory
    cp ioncube-install-assistant.php /home/username_here/www
  4. Read more…

How to run PHP 4 and 5 on Cpanel

by Tweak on June 13, 2009
in Domain/Hosting, Php, Servers

This information is helpful for hosting companies that want to run PHP 4 & 5 on the same cPanel server. After this, Hosting costumers / cPanel users should choose what version of PHP will they use on theirs scripts.

You should consider some implications on your server performance, but webhosts are using because they don’t need two server to run the different PHP versions for different costumers.

How to run PHP 4 and 5 on the same Cpanel server
Read more…

How To Install ImageMagick

by Tweak on June 12, 2009
in Php, Servers

What is ImageMagick ?

ImageMagick is a software suite for image manipulation and display, supporting close to 100 image formats, it is mainly used to perform various transformation and conversion operations on images.

How To Install ImageMagick: Read more…

Next Page »