Kurinchi Blogger Scribbles …


Archive for the ‘PHP’ Category

Oct 08
2009

PHP: Parse URL encoded GET data

Last updated: October 5th, 2009
<?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>"; 

?>
Oct 06
2009

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

Last updated: October 5th, 2009

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

Oct 05
2009

PHP: How to receive the posted XML data?

Last updated: October 5th, 2009

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);

?>
Oct 04
2009

PHP: How to post XML data using CURL?

Last updated: October 5th, 2009

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);

?>
Sep 02
2009

CakePHP: NuSoap web service call configuration

Last updated: September 3rd, 2009

This is a beginner tutorial to help beginners make a call to “wsdl” files and for them to display the results returned by the service.

First step is to include “nusoap.php” in \vendors folder in cakephp setup. In the controller, we make a call to nusoap.php by the statement App::import(‘Vendor’,'nusoap’);
(more…)

Sep 01
2009

cakephp Deprecated: PHP 5.3 Wamp

Last updated: September 2nd, 2009

Error message
cakephp Deprecated: Assigning the return value of new by reference is deprecated
You will see the above error message when you try to configure cakePHP framework using a Wamp Server installation and set the debug parameter as in

Configure::write(‘debug’, 2);

Cause: CakePHP is not PHP 5.3 ready unlike the latest version of Zend framework.

Remedy: Try downloading older version of PHP – e.g. PHP 5.2.9

Aug 31
2009

PHP removing deprecated related errors from display

Last updated: September 2nd, 2009

To remove deprecated warning message displays when executing PHP programs, open php.ini file and ADD to it

error_reporting = E_ALL & ~E_DEPRECATED

This is the setting for the production environment where you would not like to display the deprecated function related errors.

Sample error message
Assigning the return value of new by reference is deprecated in nusoap.php on line 7381

Aug 20
2009

No Framework PHP MVC framework by Rasmus

Last updated: August 20th, 2009

Read the article on No Framework PHP MVC framework written by Rasmus Lerdof (he doesn’t need an introduction!) who explains on how we could gear a simple, yet easy to manage framework with bells and whistles of Web2.0 features.

Re-read the disclaimer after you finish reading the article on the framework and the comments, so you can understand the essence of the article.

Link to No Framework
http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

Aug 11
2009

CakePHP – Bake Process

Last updated: August 10th, 2009

CakePHP Steps involved in Baking Scripts:

i) Setup cakephp by ensuring that there is no warning message in the index page after initial installation. (for this you need to change salt value in /app/config/core.php, enable /app/config/database.php)

ii) Create a database and a user for the database. After this apply the database configuration parameters to /app/config/database.php

If you are running the bake for the first time, it will ask you to create database configuration for the first time.

iii) Ensure that the path or the environment variable is set with access to PHP, MySQL executables

c:/> PATH or $ echo $PATH
(more…)

Jul 27
2009

PHP Security: Preventing Session Fixation

Last updated: August 1st, 2009

Session Fixation is method by which an intruder creates a session id which gets carried on when a user comes with that path and continues his/her activity on a website.

For e.g. an intruder may create a link to a site called samplesite.com as <a href=”http://samplesite.com/cart.php?PHPSESSID=Ax23mDud” />Sample Site<a>

When a user clicks on this link the session id gets carried on to the site ‘samplesite.com‘. The intruder waits for the user starts to perform a transaction on the site and will take over vital details by intruding user’s activity on samplesite.com.
(more…)


Valid HTML 4.01 Strict  Valid HTML 4.01 Strict