Monday, May 23, 2011

Javascript Code: A message box when page opens

You can bring a message box or a alert a window which tell something to user at the first when page opens

Javascript Code: Make your website as user's Homepage

You can put a link in you website if they click on it then your page will be their home page

Html Code: Romantic hearts following mouse cursor


Php Code: Displaying Date in the Title Bar using PHP

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

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.

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)

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)

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)

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)

Php Code: Image information

This snippet will show the information (dimensions, type, size) of an image.

Php Code: Time and date

Display time and date with PHP

Php Code: Delete all cookies set

A 3 line code snippet which will delete all cookies currently set by a website.

Php Code: MySQL connect

How to connect to a MySQL database

Php Code: Include file

create Simple file include . :)

Php Code: Petals Around the Rose

This is the ever popular Petals Around the Rose game converted to PHP!!

Php Code: Current URL with PHP

A samll function to find the current URL of the page

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.

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

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

Php Code: Check referer

Simply put the code in your sites functions.php and call it in page_head.php!
check_referer()
check_referer("./difname")

Php Code: Mysql result all

There is a PHP function named odbc_result_all which returns the query results in a table. I have frequently found it useful to have the same function for MySQL queries. This function will create a table populated with the data as well as the field names.

Usage:




$result = dbQuery("SELECT * FROM tableName");

mysql_result_all($result);




I am not a PHP master, so any improvement suggestions are welcome.

Php Code: Check a Port

ok this is great to show your users what Services you have online. i'm currently using it for it to check my Website, my IRC Server and my Eggdrop. this is great, you just upload it, change the IP or anything else and its set to go.

Php Code: Database driven page system

This stores pages into a database using an edit page and the stored pages may be viewed using the page.

Php Code: Extract Alpha Numeric Characters

This function extracts all alpha numeric letters and numbers from a string. Basically, it takes out everything that is not an alpha-numeric character, including spaces.

This function is useful in taking out excess characters before inserting data into mysql, i.e. "-" for phone numbers.

Php Code: BBCODE

This function let u use like ['u]poopoo['/u] (without ' ).
this will result in = poopoo

Php Code: Webpage Editor

Ok, who here has a host which is gay and makes you go through like 4/5 pages to get to your site to edit? Well this way, you can just visit one page and edit it.

Just upload and visit.

SUGGESTION:

Add a encryptor, i use 18 diffrent cookies which is pretty hard to get around.

Php Code: Addres on join

hope you like it

Php Code: PHP RuneScape stat function

you use it like this:

$variable = getStats("RussellReal");

and you will get a two dimensional array.

$variable[$skill][$aspect];

$aspect would be "Level" or "Exp" or "Rank"

so for example: $variable["Strength"]["Level"]; will return 89, which is RussellReals Strength Level :P

not really for looping through the values, unless you use foreachs like so:

foreach ($variable as $skill => $v) {
$line = $skill;
foreach ($variable[$skill] as $aspect => $data) {
$line .= " ".$aspect.": ".$data;
}
echo $line."\n";
}
will print a readable version of the multidimensional array. :)
will return "false" if the username doesn't exist. and somewhere in the aspects of the second dimension of the arrays will be Not Ranked. for whichever skill the user isn't ranked in. Enjoy :)

Php Code: Hide your CSS Source

It hides your CSS Source

Require a Table, like

Table -> style (must be called style unless you want to change it

Php Code: IRC

Created to be used for connecting to IRC clients using PHP on a linux system.

Php Code: Last.Fm Artist Description function

I have created a small script which will take information about an artist from last fm. (how you manipulate this is up to you)

now im sure that my script probably isn't the best way of doing what it does, but it gets the job done. If anyone wants to add comments on how to make this better please go for it.


---
How it works.

1. Artist is taken from url (http://EXAMPLE.php?artist=...)
surely you can manipulate this to work however you want..

2. File_Get_Contets takes the information from (http://www.last.fm/music/ARTIST/+wiki)

3. str_pos is used to find the position of the text above and below where the artist description is.

4. str_replace is used to replace all of this text and all of the text before and after the artist description

5. all you are left with is you're artist description which is then simply echoed...

Php Code: Source Analyzer

A source code analyzer. Searches through code in this case php files
and finds possible vulnerable syntax. This code uses (3) arrays to store
the strings to search for & one last function for custom on the fly
searches...you could even use it to search any file for any string
with minor mods.

Php Code: Strip non-ASCII characters from a String

This is a little snippet that will remove any non-ASCII characters from a string.

Php Code: PHP Slots game

This is php game . its nice ;)

Php Code: URL File Name Extractor

This is a short snippit which will give you the file name at the end of the URL. The snippint uses the pathinfo function.

Saturday, May 21, 2011

Php Code: Higher - Lower Script

Higher - Lower Script

Php Code: Encoding converter

Usage function of encoding converter on text to any format.
Often its using to convert text from windows-1251 to utf-8

Php Code: Average

just a simple function that will get the average of numbers that you picked...

Useage: $numbers = "1 4 9 10 4 8"; average($numbers);

and will return the average of them numbers ;)

Php Code: PHP to IRC Bot

This is just a simple PHP to IRC socket bot. I've got MySQL installed on mine, and it's pretty simple to do. This is just an extremely basic example, though.

Php Code: Shout box

You can create Shout box for your site . its cool :)

Php Code: Proxy filter

You can create proxy filter for your site. To pass the blocked websites. or if you do not want to show your IP.

Php Code: Calendar

You can create simple PHP Calendar that display the current month and the week and days.

Php Code: Dynamic Dropdown Menu

A function to build a basic dynamic dropdown menu, a combo box for php. You can edit the texts and the options for the visitor.

Php Code: Online user

You can see how many onlines are in your website. Basically shows a number that is the online people on your website.

Php Code: Tagcloud Font Distributor

This will assign font sizes to tags based on their counts. It tries to evenly distribute the font sizes among the tags while keeping all tags with the same counts under the same font size. The data needs to be in the following format:

$tag[tag_name] => Tag Name
$tag[tag_count] => Number of instances of this tag
$tag[tag_class] => Resulting class name, ex: tag1, tag2

Please note that this does not work with a class object. This was designed to work with an array only.

Once you create an array of these objects, you can feed them to the cloud_tags() function which will assign each $tag with a tag_class based on it's tag_count and the overall number of font sizes and tags. The return result is the array sorted aphabetically with each tag_class properly assigned.

Php Code: Date Addition and Subtraction

You can combine strtotime with the date function to create your own date verbally. This is just an alternative to using mktime that's a little more intuitive.

Php Code: Recursive Directory Browser

This function takes in a directory path and recursively searches through the directory structure and returns all files in those directories. The file list is returned in an array.


This function has 1 required parameter and 2 optional parameters.


directoryToArray(Path to Directory [,file extention [,Display Full Path]]


If the file extension parameter is set, only files matching that extension will be displayed, ie, "jpg"


If the Display Full Path parameter is true, then the full path of the file will be returned. If it is false, only the file name will be returned. By default, this parameter is set to true.

Php Code: Mysql Table Creator

Easier way to make mysql tables. very easy example of how to make SQL databases.