Category Archives: PHP Tutorial

Learn different aspects of PHP also we have created category on MySQL

Get Current file path,Directory Path, Parent Directory Path in PHP

$module_name = basename(dirname(__FILE__));
__FILE__ returns the filename of the script that is currently being run.
dirname returns the directory of a given filename.
basename() returms the filename component of path. To put it better: it strips any “parent” directories off a given string.

The constant __FILE__ in PHP always returns the absolute path to the script file that’s currently active – the PHP file in which the code line is being run right now. Function dirname() returns the directory part of the given path. Continue reading Get Current file path,Directory Path, Parent Directory Path in PHP

PHP Session Tutorial on Session Security Hijacking and Session vulnerability

A very good tutorial on session security :
http://www.supernifty.com.au/blog/2008/04/19/php-sessions-on-shared-hosting-hack-3/

Session Fixation & Session Hijacking Tutorial :
http://phpsec.org/projects/guide/4.html

How session is stored in server (Exposed Session Data) : http://phpsec.org/projects/guide/5.html

Another good tutorial on session : http://www.sitepoint.com/php-security-blunders/

PHP Heredoc example

Its like method to create string in PHP with multiple lines and almost anything in it, but without using quotations.

Example 1:

<?php
$heredocstr = <<<ANYTHING
Here you can type anything as heredoc string
Use multiple lines if required.
ANYTHING; // Closing heredoc identifier

echo $heredocstr;
?>

Caution: There should be no space or words before this word ANYTHING in the closing heredoc identifier, otherwise PARSE ERROR will be generated

heredoc starts with the <<< operator and an identifier, here ANYTHING as identifier. Start to type your text in more lines as a double quoted string. You can also use variables inside the string. To close the string write the identifier ANYTHING again in a new line as above:

Example 2:

<?php
$heredocstr = <<<ANYTHING
Here you can type anything as heredoc string
Use multiple lines if required.
You can use any $variable in heredoc string
ANYTHING; // There should be no space or words before this word ANYTHING

echo $heredocstr;
?>