This is a simple date script that displays the date in the title bar, all you do is insert the code in between the tags
Showing posts with label PHP Best Codes. Show all posts
Showing posts with label PHP Best Codes. Show all posts
Monday, May 23, 2011
Php Code: Finding Google PageRank
The following code can be used to find the PageRank of a website using PHP. Just copy & paste the below code in a php file and execute it from your browser.
Php Code: Creating Cookies using PHP
How to Create a Cookie
The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE the tag.
Syntax
setcookie(name, value, expire, path, domain);
Example
The following example sets a cookie named "uname" - that expires after ten hours.
setcookie("uname", $name, time()+36000);
?>
A cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server.
---------------------------------------------------------------------
How to Retrieve a Cookie Value
When a cookie is set, PHP uses the cookie name as a variable.
To access a cookie you just refer to the cookie name as a variable.
Tip: Use the isset() function to find out if a cookie has been set.
Example
The following example tests if the uname cookie has been set, and prints an appropriate message.
The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE the tag.
Syntax
setcookie(name, value, expire, path, domain);
Example
The following example sets a cookie named "uname" - that expires after ten hours.
setcookie("uname", $name, time()+36000);
?>
A cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server.
---------------------------------------------------------------------
How to Retrieve a Cookie Value
When a cookie is set, PHP uses the cookie name as a variable.
To access a cookie you just refer to the cookie name as a variable.
Tip: Use the isset() function to find out if a cookie has been set.
Example
The following example tests if the uname cookie has been set, and prints an appropriate message.
Php Code: Show Records by multi Columns in Rows
There are simply to show data records in table rows, just one record by one table row but sometime you need to show data records more than one record in one row. This tutorial show you how can to show your data records in the table with three columns and make multi-rows automatically with while loop.
This tutorial require 1 PHP file and 1 table of mySQL database.
1. show_multi_columns.php
2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
This tutorial require 1 PHP file and 1 table of mySQL database.
1. show_multi_columns.php
2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
Php Code: Export MySQL to Excel
Export MySQL data records to an Excel file in one PHP file, simple and easily!
This tutorial require 1 PHP file and 1 table of mySQL database.
1. export_excel.php
2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
This tutorial require 1 PHP file and 1 table of mySQL database.
1. export_excel.php
2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
Php Code: Display contents from the database
The following tutorial with code can be used to display the contents from the database into the HTML or PHP pages with formatting like 'ENTER' or 'TAB'. It will preserve the formatting as it is typed in the text area.
Php Code: Page Navigator
Most of PHP scripts as guestbook, webboard, online catalog, etc. have many records in database. So, not good idea to show them in one page. This tutorial will show you how to create the page navigator and apply it.
This tutorial require 1 PHP file and 1 table of mySQL database.
1. page.php
2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
This tutorial require 1 PHP file and 1 table of mySQL database.
1. page.php
2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
Php Code: Update Mutiple Records in 1 Form
Update your multiple data records in 1 submit form. When you have a list and need to update them in one click.
This tutorial require 2 files and 1 table of mySQL database.
1. form.php, this file shows data records in an update form.
2. update.php, this file is the updater.
3. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
This tutorial require 2 files and 1 table of mySQL database.
1. form.php, this file shows data records in an update form.
2. update.php, this file is the updater.
3. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)
Php Code: Image information
This snippet will show the information (dimensions, type, size) of an image.
Php Code: Delete all cookies set
A 3 line code snippet which will delete all cookies currently set by a website.
Php Code: Petals Around the Rose
This is the ever popular Petals Around the Rose game converted to PHP!!
Php Code: Parent , Child Category Tree
This is a simple PHP script to generate a Category Tree structure based on parent/child MySQL database. Database structure looks like this:
- category_id
- parent_id
- title
And will generate a structure like this:
Category 1
- Sub Category
- Sub, Sub Category
- Sub Category 2
Category 2
This is much simpler and works very well. The other code I found on this forum didn't work at all and was very complicated, so I wrote an easy script. Just 1 note: It's meant for a structure that does not have a root element.
- category_id
- parent_id
- title
And will generate a structure like this:
Category 1
- Sub Category
- Sub, Sub Category
- Sub Category 2
Category 2
This is much simpler and works very well. The other code I found on this forum didn't work at all and was very complicated, so I wrote an easy script. Just 1 note: It's meant for a structure that does not have a root element.
Php Code: PHP session management class with mySQL
A class to handle sessions by using a mySQL database for session related data storage providing better security then the default session handler used by PHP. You don't need to modify a thing in your application - after instantianting the class just use sessions as you would normally.
Php Code: Duration
output:
36 years 8 months 3 weeks 2 days 24 minutes 32 seconds
36 years 8 months 3 weeks 2 days
36 years 8 months
36 years 8 months 3 weeks 2 days 24 minutes 32 seconds
36 years 8 months 3 weeks 2 days
36 years 8 months
Php Code: Xml parsing
Just fixed up a old xml function I had laying around. This will return an associative array. I dug it up for a news bot Im coding, it reads google rss feeds.
Php Code: Page ID
This is a quicky script I made in 2 mins! You can create pages like:index.php?id=1 or index.php?id=forums
Subscribe to:
Posts (Atom)