Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Some Basic Php Code Snippets For All Levels Of Experience
Saint_Michael
post May 17 2007, 05:46 AM
Post #1


$p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3
*********************

Group: [HOSTED]
Posts: 6,561
Joined: 21-September 04
From: 9r33|\| 399$ 4|\|D 5P4/\/\
Member No.: 1,218
T17 GFX Crew



Most of the code snippets are usually used for community driven sites but they do give some general idea on how php works. Don't forget if your starting out php for the first time that when saving php files that you need to have the .php extension on your files or they will not work.

Display Browser info

This piece of code displays a user's browser info on how they are seeing the website

CODE
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>


Actual Display-
QUOTE
Firefox - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3

Internet Explorer - Browser Info: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; InfoPath.1; .NET CLR 2.0.50727)

Opera - Opera/9.01 (Windows NT 5.1; U; en)

Netscape - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060912 Netscape/8.1.2


Display IP Address

The next piece of code is easy to figure out, all it does is display the users current IP address and that is including using a fake IP number as well which is done by using another proxy or using a proxy site

CODE
<?php echo $_SERVER["REMOTE_ADDR"]; ?>


Display Last Modify

With this piece of code, if you remeber back in the javascript craze that there was a piece of code that would display the last tiem the page has been updated, well the same concept but in PHP

CODE
<?
//where the main page you want to display for modification
$last_modified = filemtime("thepageyouwant.php");
//print it all out
print("Page Last Edited");
print(date("m/j/y h:i", $last_modified));
?>


Display ISP host/IP number

With this piece of code it will display the ISP service you are using along with your IP number.

CODE
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;
?>



Actual Display-
QUOTE
c-75-68-74-121.hsd1.vt.comcast.net


Display Load Time

this piece of code shows a user how long it took a page to load, usually anything passed the decimal point is a bad thing, but usually hte coding is good enough that it get pretty low
CODE
<?php $load = microtime();
print (number_format($load,2));
?>


Update Copyright Date

I find this a interesting php script, which saves you about 30 seconds of updating all your pages when a new year comes, so with this little script all you do is put in your domain name and or any other info within that echo statement.

CODE
<?php

$year = date("Y"); //defines the year

echo("© $year yoursite.com"); //the echoing

?>


Thats a few I have come across and actually bookmark from the many sites I have come across, the best part you don't have to make a major alterations to these code in order for them to work. Of course for those who have being coding in php for awhile then you will be able to adapt these in your php scripts.
Go to the top of the page
 
+Quote Post
heavensounds
post May 17 2007, 12:19 PM
Post #2


Super Member
*********

Group: [HOSTED]
Posts: 492
Joined: 15-March 05
Member No.: 4,538



Hey man, thanky you for these snippets. It is nice to see something clean and simple, because usually these codes are long and complex so it is hard to understand anything if you are not a skilled programmer. I know the basics of php and this stuff is really helpful...

Thanks again for that mate,
Bye
Go to the top of the page
 
+Quote Post
wenster
post May 18 2007, 03:04 AM
Post #3


Member [Level 1]
****

Group: Members
Posts: 69
Joined: 6-May 07
From: Dallas, Texas
Member No.: 42,678



thanks i can really use the display IP address one, and display last modify.

its not that hard to use either.
Go to the top of the page
 
+Quote Post
slushpuppy
post May 18 2007, 05:19 AM
Post #4


Newbie [Level 2]
**

Group: Members
Posts: 29
Joined: 7-September 06
Member No.: 29,569



http://sg.php.net/manual/en/language.varia...es.superglobals
http://sg.php.net/manual/en/reserved.variables.php
^ Helpful links for other preset PHP variables.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How do you test your php code(80)
  2. Php Clock(7)
  3. Change Permission With Php Code(3)
  4. Adapting Html Code Embed To Work On Phpnuke(7)
  5. Dynamic Image / Signature Generator(12)
  6. Wappy's Php Snippets(13)
  7. Wap Source Code Viewer(4)
  8. You Want It, I Can Make It(49)
  9. More Dynamic ?id=browsing With Php (associative Array)(1)
  10. Display The Current Date/time(3)
  11. Use Bb Code On Your Site!(7)
  12. My Code Doesnt Resize Large Images, Please Help.(2)
  13. Php Education Class (first Code)(0)
  14. How To Make A Random 7 Number Code?(2)
  15. Whats Wrong>?(9)
  1. Awesome Source Code Viewer Script(7)
  2. Html Code Tester. Online Script(15)
  3. I Need Some Proof Reading For My Code Please! [resolved](7)
  4. Will This Code Work(5)
  5. Use Rss In Php Code(3)
  6. Php Code(15)
  7. Php Code Needed(5)
  8. Php Code?(12)
  9. Php Code Needed Iii(10)
  10. Php And Mysql Programming(2)
  11. Malicious Code Injection(3)
  12. Php Source Code Unveiled In Browser?(7)
  13. Create Table - Mysql Code - Help(1)


 



- Lo-Fi Version Time is now: 12th October 2008 - 02:17 PM