Archive for October, 2009

Oct
11
2009

Passing data from HTTPS to HTTP

Have you ever come across a situation when you need to pass data from HTTPS to HTTP controlled web pages? If you have, you would have come to know that the header values especially REFERER values become empty. Reason for this being that it is not secure to transfer data from a security controlled HTTPS layer to a non-secure site serving HTTP content.

This is one of the key points to remember if you are involved in integrating applications

Solution(s) to the above scenario
i) Transfer data between HTTPs layers instead
ii) pass GET data as query string values
iii) Programatically handle the session across the two sites behind the scenes either by storing a cookie or through database controllers

Some of the tools that comes handy in checking the Header Values are FireBug, Live HTTP Headers, HTTP Watch plugin

  • Share/Save/Bookmark
Oct
10
2009

How to include PEAR libraries with CakePHP?

Suggested solutions from other sites:
1) Modify /config/paths.php
2) Create separate php.ini settings file with the path to PEAR library
3) Modify the app_controller.php with the PEAR path settings

My preference is to add the PEAR library to the “vendors” folder and to modify the app_controller to have the PEAR path included through it.

if( file_exists(VENDORS.’Pear’)){
ini_set(’include_path’, ini_get(’include_path’) . PATH_SEPARATOR . PEAR);
}

Above solution suggested at CakePHP’s trac

Depending on the library that you want to get included in the programs, add the library to the respective view

App::import(’vendor’, ‘XML_Feed_Parser’, array(’file’ => ‘../vendors/pear/XML/Feed/Parser.php’));

  • Share/Save/Bookmark
Oct
09
2009

PHP: What is PEAR?

PEAR stands for PHP Extension and Application Repository.

To learn more about the PEAR library click here

If you are beginner, the following link will help you tread with the library usage PEAR Manual

Installation instructions clearly walks through the steps for PEAR configuration. There may be cases where you may want to use PEAR libraries for specific projects only in which case you can install PEAR library for that specific purpose. To use it in projects, PEAR path should be set in php.ini settings or should be included in the project configuration’s physical path.

  • Share/Save/Bookmark
Oct
08
2009

PHP: Parse URL encoded GET data

<?php
// To build back the URI and to extract the passed parameters, you can use parse_url, parse_string function
$extract_string = parse_url($pass_string);
echo "<h2>Extracted URI (using parse_url)</h2><br />";
echo "<pre>";
var_dump($extract_string);
echo "</pre>";

// To decode the query string use parse_str function
parse_str($extract_string["query"], $extract_query);
echo "<h2>Extracted Query String (using parse_str)</h2><br />";
echo "<pre>";
var_dump($extract_query);
echo "</pre>"; 

?>
  • Share/Save/Bookmark
Oct
07
2009

Minimum Hardware Requirements for Linux Install

As indicated by Red Hat …

CPU - Pentium type, 200 MHz for text mode
Hard disk space – 475 MB
Memory - 64 MB for text mode

  • Share/Save/Bookmark
Oct
06
2009

PHP: Program to pass data using character encoding (GET Parameter)

PHP program to pass data as GET parameters

<?php
// PHP 5 how to pass data as a query string
/*
http_build_query is a function in PHP 5 that enables you to URL encode the query string. You can pass an array or an array of array to this function. The default separator is "&"
*/

$data = array("first_name" => "Robert",
                "last_name" => "Brown",
                "address" => "123 Adam St., New York"
            );

// URI formatted with character encoding
$pass_string = "http://localhost/demo.php?".http_build_query($data, '');

echo "<h2>Query URI (using http_build_query)</h2><br />";
echo $pass_string;
?>

Ouput from the above execution:
Query URI (using http_build_query)
http://localhost/demo.php?first_name=Robert&last_name=Brown&address=123+Adam+St.%2C+New+York

  • Share/Save/Bookmark
Oct
05
2009

PHP: How to receive the posted XML data?

Receive the posted XML data

In order to test the posted data, we can create a file creation steps to ensure that we receive the posted data via the $_POST array

<?php
/*
  File name: postdata2.php
*/
    $xmlFile = "xmlFile.txt";
    $fh = fopen($xmlFile, 'w') or die("Cannot open file");
    fwrite($fh, $_POST["xmldata"]);
    fclose($fh);

?>
  • Share/Save/Bookmark
Oct
04
2009

PHP: How to post XML data using CURL?

During integration projects or during such similar situations you may have across a necessity to transfer XML data or plain text file across server locations.

Curl comes in handy during such scenarios. Following program is used to post XML data using Curl. In order for Curl to function, ensure that PHP settings has the curl module installed and that the libraries/dll libeay32, ssleay32 is installed in your server.

<?php
/*
  File name: postdata.php
*/

$post_url = "http://localhost/demo/postdata2.php";
$xml_string = '<?xml version="1.0" encoding="UTF-8"?>
<books>
<book isbn="978-1594489587">
    <title>The Brief Wondrous Life of Oscar Wao</title>
    <publisher>Riverhead Hardcover </publisher>
    <amazon_price>14.97 </amazon_price>
    <author_firstname>Junot </author_firstname>
    <author_lastname>Diaz </author_lastname>
  </book>
<book isbn="999-1594489501">
    <title>A Thousand Splendid Suns </title>
    <publisher>Riverhead Hardcover </publisher>
    <amazon_price>14.27 </amazon_price>
    <author_firstname>Khaled </author_firstname>
    <author_lastname>Hosseini </author_lastname>
  </book>
</books>';

$ch = curl_init($post_url);

curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "xmldata=".$xml_string);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

$data = curl_exec($ch);
// to get information on the curl resultset
$info = curl_getinfo($ch);

if(curl_errno($ch)){
    print curl_error($ch);
}

curl_close($ch);

?>
  • Share/Save/Bookmark
Oct
03
2009

Javascript Memory Leak Diagnosis

What is meant by Memory leak?
Memory leakage refers to obtrusive memory handling techniques adopted in programs which leads to increased load time and poor performance.

Various scenarios can cause memory leaks which can range from unhandled memory garbage to cyclic references to error in code logic. One best suggestion given in the javascript forums to overcome this problem is to nullify the element once its usage is over.
(more…)

  • Share/Save/Bookmark
Oct
01
2009

Javascript code organization for optimized performance

Knowing how javascript code gets executed in a browser will help us organize the libraries or functions for better performance.

Javascript unlike the server side scripting languages like PHP, ASP, Perl is not compiled at the server side. It is sent as-is from the server to the browser client and it is the browser that interprets the code at the client side.

The total size of the Javascript code and its organization will have a significant effect on the pages served at the client side which in turn will affect the performance of the page.

Organize the libraries in such a fashion that you only have the needed functions associated with the page. You can consider this point right at the time of creating your template pages. This will reduce the number of javascript pages that are called from one page. (more…)

  • Share/Save/Bookmark