PHP tips(Mega Post)
PHP is a widely-used scripting language that is suited for web
development and can be embedded into HTML. PHP is used in many websites
on the internet. I have compiled a list of 15 top PHP coding tutorials and tips / tricks
to help you better understand it. These should keep you busy for a
while. They all can come in handy sometime when you are coding.
http://www.jooria.com/Limit-Characters-From-Your-Text-a139.html
http://net.tutsplus.com/tutorials/php/creating-an-advanced-password-recovery-utility/
http://www.electrictoolbox.com/google-analytics-login-php-curl-username-password/
http://net.tutsplus.com/tutorials/php/404403-website-error-pages-with-php-auto-mailer/
http://www.milesj.me/resources/script/session-manager
http://www.prodevtips.com/2009/03/26/simple-php-class-for-parsing-markup/
http://www.akshitsethi.me/how-to-create-rss-feed-in-php/
http://www.akshitsethi.me/a-basic-wikipedia-scraper/
http://hubpages.com/hub/Simple-PHP-web-based-address-book-using-MySql
http://www.webdesignermag.co.uk/tutorials/enabling-single-signon-using-open-id-login-php-and-mysql/
Limit Characters From Your Text
In this tutorial you will learn how to limit characters from a sentence without cutting words up. This is a really useful tutorial for begginer web developers. You’ll learn how it’s done in this helpful step by step tutorial.http://www.jooria.com/Limit-Characters-From-Your-Text-a139.html
Create An Advanced Password Recovery Utility
Learn how to create a very advanced password recovery tool using PHP. This can be useful, and you can implement it in to your website login system. This PHP coding tutorial teaches you how to handle encrypted and unencrypted passwords, basic mySQLi functions, and how to also build in a temporary lockout if the user answers the security question incorrectly too many times.http://net.tutsplus.com/tutorials/php/creating-an-advanced-password-recovery-utility/
Login To Analytics API Using PHP
Great little tip / trick that teaches you how to login to the Google Analytics API using ClientLogin.http://www.electrictoolbox.com/google-analytics-login-php-curl-username-password/
Error 404 Pages With PHP Auto-Mailer
Website error pages are perhaps one of the most overlooked pages of a website. This is an awesome tutorial for creating a custom error 404 page. This tutorial teaches you how to spice up the design a bit, add basic navigation and link to the website’s sitemap.http://net.tutsplus.com/tutorials/php/404403-website-error-pages-with-php-auto-mailer/
Resession (Session Manager)
Check this out. Its a really nifty session manager that you can integrate with your website.http://www.milesj.me/resources/script/session-manager
Simple PHP Class For Parsing Markup
This tutorial will teach you how to make a simple class that wraps PHP’s various regex functions in a fluent interface.http://www.prodevtips.com/2009/03/26/simple-php-class-for-parsing-markup/
How to: Create RSS Feed in PHP
RSS is an easy way to make your content global and available to various platforms. In this tutorial, you’ll find out how easy it is to create feeds for your content in PHP.http://www.akshitsethi.me/how-to-create-rss-feed-in-php/
A basic Wikipedia scraper
Any info you need, be sure you’ll find it on Wikipedia! In this tutorial, you’ll learn how you can build a small scraper in PHP to fetch basic information about any topic from Wikipedia.http://www.akshitsethi.me/a-basic-wikipedia-scraper/
PHP Based Address Book Using MySQL
Learn how to create a PHP address book and store all the addresses in a MySQL database with this helpful PHP coding tutorial.http://hubpages.com/hub/Simple-PHP-web-based-address-book-using-MySql
Single Signon Using OpenID, PHP and MySQL
Enable your website / web application to accept OpenID as a way of login. In this tutorial you’ll have a look at how you can enable your site for Open ID logins. You’ll be using PHP and MySQL.http://www.webdesignermag.co.uk/tutorials/enabling-single-signon-using-open-id-login-php-and-mysql/
Creating a File & Downloading It Using PHP
In this PHP coding tutorial, you will learn how to create a file using PHP, and then enable your users to download it. The tutorial will teach you how to get a user’s ip, place it in a text file, and have the ‘download it all’ without the text file being stored on your server for more than a few seconds.
Today
I’ll show you how to get a user’s ip, stick it in a text file, and have
the download it all without the text file being stored on your server
for more than a few seconds.
Step 1: Getting the I.P Address
To get the ip address, we use this code:
So when we put it as a varible:
Step 2: Creating the file
Now that we have the user’s ip address stored in a varible, we want to put it in a file.
So first, we need to create the file:
If you notice, we are using hte person’s ip address for the file name.
Now here is the final piece of that code:
Step 3: Writing to the file
So we have the file created and now we need to write to it. Use this code to do so:
Note that it writing the ip address to our file
Step 4: Close it
Not much for this:
Step 5: Forcing it
Now that we have the file created and with the ip adress in it, we have to make the browser be “forced” into downloading it
I’ll explain all that in a later tutiral.
Step 6: Deleting the file
To delete the file, all we need to do is this:
Note that it deletes the file named after that ip adress
Final Code
Final Thoughts
To make the file download as a text file, you’ll need to stick an txt extension on the ip adress. I used this code to do so:
Also, its not secure, so I would clean it up before using it
All the best!
Step 1: Getting the I.P Address
To get the ip address, we use this code:
$_SERVER['REMOTE_ADDR'];
So when we put it as a varible:
$ip = $_SERVER['REMOTE_ADDR'];
Step 2: Creating the file
Now that we have the user’s ip address stored in a varible, we want to put it in a file.
So first, we need to create the file:
fopen($ip, 'w') or die("die");
If you notice, we are using hte person’s ip address for the file name.
Now here is the final piece of that code:
$file = fopen($ip, 'w') or die("die");
Step 3: Writing to the file
So we have the file created and now we need to write to it. Use this code to do so:
fwrite($file, $ip);
Note that it writing the ip address to our file
Step 4: Close it
Not much for this:
fclose($file);
Step 5: Forcing it
Now that we have the file created and with the ip adress in it, we have to make the browser be “forced” into downloading it
$filepath = "/home/manywor/public_html/phptest/";
$file = $filepath . $ip; header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary"); header("Content-length: ".filesize($file));
header("Content-disposition: attachment;filename=\"".basename($file)."\""); readfile($file);
I’ll explain all that in a later tutiral.
Step 6: Deleting the file
To delete the file, all we need to do is this:
unlink($ip);
Note that it deletes the file named after that ip adress
Final Code
//Get the IP Address of the user
$ip = $_SERVER['REMOTE_ADDR'];
//Create and close the text file
$file = fopen($ip, 'w') or die("die");
//Write to the text file
fwrite($file, $string);
//Close it fclose($file);
//Force it
$filepath = "/home/manywor/public_html/phptest/";
$file = $filepath . $ip; header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment;
filename=\"".basename($file)."\""); readfile($file);
//Delete it
unlink($ip);
Final Thoughts
To make the file download as a text file, you’ll need to stick an txt extension on the ip adress. I used this code to do so:
//Replace the dots in it
$ip =str_replace(".","",$ip);
//Turn the IP into a text extention
$extiontion = ".txt";
$ip = $ip .''. $extiontion;
Also, its not secure, so I would clean it up before using it
All the best!
Comments
Post a Comment