Dzhuneyt Ahmed

Dzhuneyt Ahmed

Archive for January 2011

← Go back to homepage

Simple PHP Script to Send Email with Mail()

There are three requirements for sending email through a PHP script: A form, an email processing script, and PHP’s mail() function to be enabled (most hosts have this enabled, but some shared hosts don’t). Place this inside a file called mail.html Your Message \[ad name=”In Post”\] The email processing script should be inside a file

How to Create a PHP Redirect?

Sometimes you want to hide an affiliate link, sometimes you may want to log each downloads of a file or just redirect the user to a site through your script. This is where PHP redirection comes handy. The syntax is as follow: header(“Location: http://ephp.info”); die(); \[ad name=”In Post”\] Just replace the URL with the page
Download Remote File Using CURL and PHP

Download Remote File Using CURL and PHP

Sometimes you need to download URL’s contents using the CURL library, included inside PHP (e.g if you want to use a web-based API, provided by service like TinyURL, Digg, Twitter). It’s actually very simple and faster to use than other methods of downloading remote file like the file(), file\_get\_contents() or fsockopen(). Also, CURL is very

PHP Script to Show Visitor’s IP Address

Sometimes you want to get the visitor’s IP address (e.g to show it to him or for logging purposes). This simple snippet does the job: $ip = $\_SERVER\[‘REMOTE\_ADDR’\]; Also, if you have REGISTER\_GLOBALS turned on on your server, you can use the shorter version: $ip = @$REMOTE\_ADDR; Then you can easily use the variable called

Top Online IDEs to Test Your PHP Code

Sometimes you don’t have an Apache server on your PC and you don’t want to go through the hassle of uploading your PHP script to your web hosting space just to test if your tweaks inside the code work. Sometimes you just need to paste the code inside the IDE (Integrated Development Environment) and see

Convert Text to Barcode Image

Thanks to a skilled PHP programmer, the internet has a ready made PHP script that takes a text string and returns an image representation in barcode format. Here’s the complete script: =1 to enable NOTE: You must have GD-1.8 or higher compiled into PHP in order to use PNG and JPEG. GIF images only work

How to kill PHP (on purpose)

1\. Stack overflow (e.g calling a function inside itself). function a() { a(); } a(); First you define a function called a() and the function’s sole purpose is to call itself again, causing an infinite loop. Then you just call the function. 2\. Excessive Memory Allocation Using str\_repeat str\_repeat(“a”, 10000000000); The above code will cause

Easy PHP Debugging

Spotting errors inside PHP is a difficult task. Especially if you try to understand the default messages, given by the PHP interpreter. If you want to effectively debug your PHP script, you can use the following code: error\_reporting(E\_ALL); This code will show all errors, notices and warnings generated during the script’s run. It’s very useful

Connect to a MySQL Database

This is the very basic step, needed to work with MySQL databases. Before trying to do any actions on the database itself, such as: creating tables, querying rows, dropping tables or else, you have to make your PHP script connect to the MySQL database. $host = “mysql\_host”; $user = “mysql\_user”; $pass = “mysql\_password”; $db =