PHP Web Development Tools

Here’s a list of development tools that I use when developing PHP and website code (HTML, javascript,CSS) :

Netbeans IDE for php code highlighting, auto complete, DB2 access, Source Control, Debugging, and auto-FTP
Filezilla for FTPing
Firebug (Firefox Extension) for HTML and Javascript edits and debugging in real-time
HTTPFox (Firefox Extension)  for checking HTTP requests and responses from the server
Web Developer  (Firefox Extension) I started using this before Firebug and I’m just used to some its tools that it provides.
Notepad++ for quick edits and its multiple folder search,
Iseries navigator for IBM i specific tasks,
Winmerge for merging files,
Tortoise SVN for easily using SVN with windows explorer ,
Visio 2007 for diagramming,
Putty for SSH,
Launchy so i can press alt+space for quick access to start a program.

I used to use Dia for diagramming since it was open source option and didnt have to pay M$ for Visio.

SugarCRM Report Export bug

April 25, 2012 2 comments

I recently had a problem exporting reports. I just upgraded from SugarCRM Pro 5.5.1 to 6.4.3. After stepping through the javascript code in Firebug I found that there was a programming typo in an IF statement. Instead of testing if filter.name is equal to ‘user_name’ the if statement has only one equal sign which assigns the filter.name to ‘user_name’. This was changing my custom column name to user_name. This data is posted to the server when you export and I kept getting the error:

The following field in this report is no longer valid: user_name. Please Edit the report and check to make sure that the other parameters are still relevant.

If you look at include/javascript/reportCriteria.js you’ll find this on line 127:

if((option_value==filter.input_name0)||(<strong>filter.name='user_name'</strong>)&&(filter.input_name0=='Current User')&&(option_value==current_user_id)){selected=true;}
else{selected=false;}

You should change filter.name=’user_name’  to filter.name==’user_name’.

Code Fix:
if((option_value==filter.input_name0)||(filter.name==’user_name’)&&(filter.input_name0==’Current User’)&&(option_value==current_user_id)){selected=true;}
else{selected=false;}

Tool to make your webpage images load faster

I just found this cool tool yahoo made to optimize your images and not lose any quality.  You can check it out here:

Smush all our images so they load quicker.

Dynamic Canonical Link using PHP Script value

February 18, 2011 Leave a comment

This is some simple PHP code I created to dynamically generate the canonical link that search engines want so they can tell what your site url is.  Remember site’s loose link power juice when search engines find duplicate content (i.e. www.example.com, example.com, example.com/index.php are the same exact content)


if ($_SERVER["SCRIPT_NAME"] == "/index.php")
{
 $canonical = "http://www.example.com";
}
else
{
 $canonical = "http://www.example.com" . $_SERVER["SCRIPT_NAME"];
}

<head>

<!--Somewhere in the head tag-->
<link rel="canonical" href="<?php echo $canonical; ?>" />

</head>
<pre>

In your Htaccess file make sure your traffic is all going to 1 base url.  In this case I want example.com, example.org, and www.example.org to all go to www.example.com.

</pre>
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^example.org [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www.example.org [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
<pre>

Categories: Uncategorized

PHP DOS Exploit affecting 32 bit linux and windows

If your running PHP on a 32 bit machine you might want to look into updating very soon.  There is a simple exploit that can cause your server to hang until the max execution time has hit.

<?php
$d = 2.2250738585072011e-308;
?>

So if that value were able to be passed in a post or get variable and then your php code assigned that value to a variable your system would hang.

Discovered 2010-12-30

Fixed in PHP Version 5.3.5 and 5.2.17

Download the fixed versions here: http://php.net/downloads.php


More info:
http://bugs.php.net/bug.php?id=53632

http://www.zend.com/en/company/news/news-links/php-remote-exploit-information-and-hotfix

Printing PDFs using PHP and Linux

December 29, 2010 Leave a comment

To print using PHP we’ll use the shell_exec command to run the lpr command to print the document.  Here’s the code:


//specify the pdf you'd like to print
$file = '/var/www/data/myfile.pdf';

//Change PrinterName to the name of the printer you set up in CUPS
$cmd = "lpr -PPrinterName ";
//append any files you'd like to print to the end of the command
$cmd .= $file;

//Runs "lpr -PPrinterName  /var/www/data/myfile.pdf" and brings back any output to the console.

$response = shell_exec($cmd);

If you need help setting up a linux printer please refer to the cups link below.  They have a get started guide.

References

http://www.cups.org/ - CUPS is the standards-based, open source printing system

Shell_Exec – PHP shell_exec manual

Categories: PHP Tags: , , , , , , ,

Merging PDFs using PHP & GS

December 28, 2010 2 comments

Merging PDFs using PHP shell_exec command

 

You can also merge multiple PDF documents using PHP and the gs command by adding additional filenames at the end of the command.

//location of input and output directory
$datadir = "/var/www/data/";

$outputTiffFileName = $datadir."Merged.pdf";
$fileArray = array($datadir."1.pdf",$datadir."2.pdf",$datadir."3.pdf");

//ghost script command to run
$cmd = "gs -SDEVICE=tiffg4 -r600x600 -sPAPERSIZE=letter -sOutputFile=$outputTiffFileName -dNOPAUSE -dBATCH ";
//Add each pdf file to the end of the command
foreach($fileArray as $file)
{
    $cmd .= $file." ";
}

//Execute the ghost script that merges multiple PDFs and saves the it in the data directory.
$response = shell_exec($cmd);

Make sure you have write permission to the directory your saving the files too, and that you have read permissions.

References

chmod – how to change permissions

Follow

Get every new post delivered to your Inbox.