Forums Gallery Movies File Hosting Classifieds Jokes Free Hosting Free Blogs

Go Back   BizHat Forums > Computer Forum > PHP Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2008, 06:48 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default Tips & Tricks in PHP

Web Server Configuration & .htaccess File


Some web servers may ignore .htaccess files unless otherwise configured. Make sure that your web server is configured to read the .htaccess file in your public directory.
Reply With Quote
  #2 (permalink)  
Old 12-11-2008, 06:51 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default

Best Practices and Closing Tags

File Name :
phpinfo.php
Purpose :
To display the PHP environment variable values
Quote:
Code :

<?php phpinfo() ;

We didn't forget the closing (?>) PHP tag! We intentionally omit it to avoid unintentional output of whitespace in the response in certain cases.
Reply With Quote
  #3 (permalink)  
Old 12-18-2008, 09:37 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default PHP tips

PHP is a famous open source language, which decrease application performance considerbly.

Turn On Error Reporting Immediately during development stage by


Code:
error_reporting(E_ALL);


Single Quotes and Double Quotes are Very Different


echo "Today is the $day of $month";

Instead use the following code :

Code:
echo 'Today is the ' . $date[‘day’] . ' of ' . $date['month'];


Use /*…*/ commenting system to document your code.


It will help in the development of the code or during debugging.
Reply With Quote
  #4 (permalink)  
Old 12-18-2008, 09:54 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default Error Reporting in php

Set display_errors value in php.ini set to "0". Otherwise, any errors that are encountered in your code, such as database connection errors, will be output to the end user's browser. A malicious user can learn about the lopphole in the security and can hack the system.

Instead of displaying errors, set the error_log ini variable to "1" and check your PHP error log frequently for caught errors. Alternatively, you can develop your own error handling functions that are automatically invoked when PHP encounters an error, and can email you or execute other PHP code of your choice.

Learn more about the set_error_handler() function from PHP manual.
Reply With Quote
  #5 (permalink)  
Old 12-18-2008, 10:42 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default Home page with random background color

Code tested in Firefox browser as random.php

Code:
<?php

$r = rand(128,255);
$g = rand(128,255);
$b = rand(128,255);

$tablebg = dechex($r) . dechex($g) . dechex($b);

?>
<html>
 <head>
  <title> Refresh and see </title>
 </head>
 <body bgcolor='<?php echo "#"."$tablebg"; ?>'>

 This is my Home page with random background color. <br>
 Refresh and see.

 </body>
</html>
Light colors are selected using $r = rand();. If you change the $r = rand(128,255); to $r = rand(0,255); deep color will be set as background color, which will cause difficulty in reading the text in the web page.
Reply With Quote
  #6 (permalink)  
Old 12-18-2008, 10:49 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default Security tips

The phpinfo() function will list your php.ini variables and scan them for insecure settings. Keep this page in a restricted place and do not allow public access to it. The output of phpinfo() contains information that a potential hacker might find extremely useful.

Code:
<?php phpinfo() ;
Some settings to consider when configuring PHP for security include:
  1. register_globals: It has to be changed to "off". It exports all user input as global variables.
  2. safe_mode: The safe mode setting can be very useful to prevent unauthorized access.
  3. disable_functions: This setting can only be set in your php.ini file, not at runtime. It can be set to a list of functions that you would like disabled in your PHP installation. It can help prevent the possible execution of harmful PHP code. Some functions that are useful to disable if you do not use them are system and exec, which allow the execution of external programs.
Reply With Quote
  #7 (permalink)  
Old 12-25-2008, 11:04 AM
Administrator
Site Admin
 
Join Date: Sep 2006
Location: Pune
Posts: 3,632
Default Tips

* By default the index.php file is included in the URL, but it can be removed using a simple .htaccess file.

* Programmers love to code and hate to write documentation. Well documented program is easy to rebuild and debug.

* The only way to really judge an application is to try it and get to know the code.
Reply With Quote
Reply

Bookmarks

Tags
.htaccess, php, tips & tricks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:43 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0