Archive for December 2012

category/tmp/blog_item

defined('_JEXEC') or die('Restricted access'); ?>
user->authorize('com_content', 'edit', 'content', 'all') || $this->user->authorize('com_content', 'edit', 'content', 'own')); ?>
item->state == 0) : ?>




item->params->get('show_title') || $this->item->params->get('show_pdf_icon') || $this->item->params->get('show_print_icon') || $this->item->params->get('show_email_icon') || $canEdit) : ?>


item->params->get('show_title')) : ?>



item->params->get('show_pdf_icon')) : ?>



item->params->get( 'show_print_icon' )) : ?>



item->params->get('show_email_icon')) : ?>







item->params->get('link_titles') && $this->item->readmore_link != '') : ?>

escape($this->item->title); ?>


escape($this->item->title); ?>


item, $this->item->params, $this->access); ?>

item, $this->item->params, $this->access); ?>

item, $this->item->params, $this->access); ?>

item, $this->item->params, $this->access); ?>


item->params->get('show_intro')) :
echo $this->item->event->afterDisplayTitle;
endif; ?>
item->event->beforeDisplayContent; ?>

item->params->get('show_section') && $this->item->sectionid) || ($this->item->params->get('show_category') && $this->item->catid)) : ?>





item->params->get('show_author')) && ($this->item->author != "")) : ?>





item->params->get('show_create_date')) : ?>





item->params->get('show_url') && $this->item->urls) : ?>









item->modified) != 0 && $this->item->params->get('show_modify_date')) : ?>





item->params->get('show_readmore') && $this->item->readmore) : ?>






item->params->get('show_section') && $this->item->sectionid && isset($this->item->section)) : ?>

item->params->get('link_section')) : ?>
item->sectionid)).'">'; ?>

item->section; ?>
item->params->get('link_section')) : ?>
'; ?>

item->params->get('show_category')) : ?>




item->params->get('show_category') && $this->item->catid) : ?>

item->params->get('link_category')) : ?>
item->catslug, $this->item->sectionid)).'">'; ?>

item->category; ?>
item->params->get('link_category')) : ?>
'; ?>





item->created_by_alias ? $this->item->created_by_alias : $this->item->author) ); ?>

  

item->created, JText::_('DATE_FORMAT_LC2')); ?>


item->urls; ?>


item->toc)) : ?>
item->toc; ?>

item->text; ?>

item->modified, JText::_('DATE_FORMAT_LC2'))); ?>


item->readmore_register) :
echo JText::_('Register to read more...');
elseif ($readmore = $this->item->params->get('readmore')) :
echo $readmore;
else :
echo JText::sprintf('Read more...');
endif; ?>


item->state == 0) : ?>


 
item->event->afterDisplayContent; ?>

Php Magic constants

PHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in.

There are five magical constants that change depending on where they are used. For example, the value of __LINE__ depends on the line that it's used on in your script. These special constants are case-insensitive and are as follows:

A few "magical" PHP constants

Name

Description

__LINE__

The current line number of the file.

__FILE__

The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.

__FUNCTION__

The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

__CLASS__

The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

__METHOD__

The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

special data types in php

                                     resource data types and null data types




resource data types refers the external resources  like data connection , file pointer , FTP connection ...ect


<?php

mysql_connect("hostname",username","password");

?>

<?php

$con=mysql_connect("hostname",username","password");
echo $con;

?>

here con is external resource type

output :    resource #id2
                                                                  null data type



null is not a value

the variable not initialized with any  value
the variable initialized with null value
if the value of the variable is removed using unset function

based on by that 3 conditions we consider a variable has null value


<?php

$a=100;
unset($a);
echo is_null($a);

?>

output :  1

if is it null returns 1 else returns nothing




Image uploading in PHP

Simple image uploading script in PHP.
First; create a file, and copy-paste above code into this file.  After your form is fine, create a new file that named upload.php this file contains our main uploading action. When you are done, create a folder where we store images. That is all, now you can upload images.


<!-- Form Area -->
<form enctype= "multipart/form-data" action= "upload.php" method= "post" >
Select Image: <input type= "file" name= "userfile" >
<input type= "submit" value= "Upload!" >
</form>
<!-- Form Area -->


<?php

# Variables
$path = "images/"
$max_size = "200000" ;

# File
$filename = $_POST [ 'userfile' ] ;

# Control
if ( !isset ( $HTTP_POST_FILES [ 'userfile' ] ) ) exit;

if ( is_uploaded_file ( $HTTP_POST_FILES [ 'userfile' ] [ 'tmp_name' ] ) ) {

if ( $HTTP_POST_FILES [ 'userfile' ] [ 'size' ] >$max_size ) {
echo "The File is Too Big. The Max File Size is $max_size KB<br>n"
exit; 
}

# Type Control
if (
( $HTTP_POST_FILES [ 'userfile' ] [ 'type' ] == "image/gif" )    ||         
( $HTTP_POST_FILES [ 'userfile' ] [ 'type' ] == "image/jpg" )    ||   
( $HTTP_POST_FILES [ 'userfile' ] [ 'type' ] == "image/bmp" )    ||
( $HTTP_POST_FILES [ 'userfile' ] [ 'type' ] == "image/png" )    ||
( $HTTP_POST_FILES [ 'userfile' ] [ 'type' ] == "image/jpeg" )
)
{

# If File Exist
if ( file_exists ( $path . $HTTP_POST_FILES [ 'userfile' ] [ 'name' ] ) )
{
echo "A File With That Name Already Exists!<br>"
exit; 
}

$res = copy ( $HTTP_POST_FILES [ 'userfile' ] [ 'tmp_name' ] , $path .

$HTTP_POST_FILES [ 'userfile' ] [ 'name' ] ) ;
if ( !$res ) {
echo "Upload Failed!<br>"
exit; 
}
else {
echo "Upload Sucessful!<br>"
}

echo "File Name: " .$HTTP_POST_FILES [ 'userfile' ] [ 'name' ] . "<br>" ;
echo "File Size: " .$HTTP_POST_FILES [ 'userfile' ] [ 'size' ] . " bytes<br>" ;
echo "File Type: " .$HTTP_POST_FILES [ 'userfile' ] [ 'type' ] . "<br>" ;
echo "<a href=$path" .$HTTP_POST_FILES [ 'userfile' ] [ 'name' ] . ">View Image</a>" ;
}
else
{
echo "Wrong File Type<br>"
exit; 
}
}

?>

Qué es PHP?

PHP (acrónimo de "PHP: Hypertext Preprocessor") es un lenguaje de "código abierto" interpretado, de alto nivel, embebido en páginas HTML y ejecutado en el servidor.

Una respuesta corta y concisa, pero, ¿qué significa realmente? Un ejemplo nos aclarará las cosas:

 

<html>

<head>

<title>Ejemplo</title>

</head>

<body>

<?php

echo "Hola, soy un script PHP!";

?>

</body>

</html>

Puede apreciarse que no es lo mismo que un script escrito en otro lenguaje de programación como Perl o C -- En vez de escribir un programa con muchos comandos para crear una salida en HTML, escribimos el código HTML con cierto código PHP embebido (incluido) en el mismo, que producirá cierta salida (en nuestro ejemplo, producirá un texto). El código PHP se incluye entre etiquetas especiales de comienzo y final que nos permitirán entrar y salir del modo PHP.

Lo que distingue a PHP de la tecnología Javascript, la cual se ejecuta en la máquina cliente, es que el código PHP es ejecutado en el servidor. Si tuviésemos un script similar al de nuestro ejemplo en nuestro servidor, el cliente solamente recibiría el resultado de su ejecución en el servidor, sin ninguna posibilidad de determinar qué código ha producido el resultado recibido. El servidor web puede ser incluso configurado para que procese todos los archivos HTML con PHP.

Lo mejor de usar PHP es que es extremadamente simple para el principiante, pero a su vez, ofrece muchas características avanzadas para los programadores profesionales.

PHP Environment


In order to develop and run PHP Web pages three vital components need to be installed on your computer system.
  • Web Server - PHP will work with virtually all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely available Apache Server. Download Apache for free here: http://httpd.apache.org/download.cgi
  • Database - PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. Download MySQL for free here: http://www.mysql.com/downloads/index.html
  • PHP Parser - In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on your computer.
PHP Parser Installation:
Before you proceed it is important to make sure that you have proper environment setup on your machine to develop your web programs using PHP.
Type the following address into your browser's address box.
If this displays a page showing your PHP installation related information then it means you have PHP and Webserver installed properly. Otherwise you have to follow given procedure to install PHP on your computer.
This section will guide you to install and configure PHP over the following four platforms:
Apache Configuration:
If you are using Apache as a Web Server then this section will guide you to edit Apache Configuration Files.
PHP.INI File Configuration:
The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality.
Just Check it here: PHP.INI File Configuration
Windows IIS Configuration:
To configure IIS on your Windows machine you can refer your IIS Reference Manual shipped along with IIS.

How to get XML/HTML result set with mysql

you can get directly HTML,XML format of your resultset by just executing the query by following syntax.

uttam@uttam:~$ mysql -u[userName] -p -H -e "[query]" [database]

where -H is to get HTML resultset.you can replace this with -X to get XML output.
-e is to execute the query specified.

go to the shell promt. and thry this example.
mysql -uroot -p -H -e "select * from user" mysql




running perl script in apache

Perl script can be run as executable files in apache.All you have to do is to follow some basic steps given below.

open your apache.conf file in write mode and add the following line.by default it's under /etc/apache2/ directory.

AddHandler cgi-script .cgi .pl

save the file.

Next, search for the line that says " in the file. It should look something like this:[In this case /var/www/ is the document root.]


Options FollowSymLinks
AllowOverride None


Add "+ExecCGI" to the options list. The line now looks like this:
Options FollowSymLinks +ExecCGI

generally you can find this in sites-enabled/000-default file.

Restart your apache web server.

test by typing URL of your perl script in web browser.

ListContains

The ListContains function is a quick and easy function to use. The ListContains function determines the index of the first list element that contains the specified substring. If the substring can not be found in the list, The ListContains function will returns zero. This function will not ignore empty sets; thus the list "a,b,c,,,d" has 8 elements
 
The Function:
<php
function ListContains($list,$substring,$delimiter=",")
{
    $delimiter = substr($delimiter,1);
    $a = explode($list,$delimiter);
    $return = 0;
    for($i=0;$i< count($a);$i++)
    {
        if(strstr($a[$i],$substring))
        {
            $return = $i + 1;
        }
    }
    return $return;
}

?>
Usage:
Using the ListContains function is simple:
 
<?php
    $list = "one,two,three";
    $substr = "two"
    if(ListContains($list,$substr) > 0)
    {
        echo $substr . " found at position " . ListContains($list,$substr):
    }
?>

The output of this function will be: two found at position 2

read a file in php

<?php

if(isset($_POST['filename']))
{
  if(!empty($_POST['filename']))
  {
    $file=$_POST['filename'].'.txt';
    if(file_exists($file))
    {
         $filename = fopen("$file", "r") ;
         while(!feof($filename))
               {
                 echo fgets($filename)."<br>";
               }
         fclose($filename);
    }
    else
    echo 'file not exits';
  }
 else
echo 'empty';

}
?>

<form action="file-read.php" method="POST">
<input type="text" name="filename">
.txt
<input type="submit" value="submit">
</form>

output :
1)enter the file name for read that file
2)that file must be text file

ex :        test.txt

ListDeleteAt

The ListDeleteAt function is a neat little coldfusion function and works just as well in PHP. This function is good for removing counted values from lists. I use it a lot in conjunction with other list functions.
The Function:

<php
function ListDeleteAt($list,$position,$delimiter)
{
$delimiter = substr($delimiter, 1);
$a = explode($delimiter,$list);
for($i=0;$i<count($a);$i++)

{
if($i != $position)
{
if(! isset($return))
{
$return = $a[$i];
}
else
{
$return .= $delimiter . $a[$i];
}
}
}
return $return;
}
?>

Usage:

To use the ListDeleteAt function with the default delimiter ',':

<php
$list = "a,b,c,d,e,f,g";

$position = 3;
echo ListDeleteAt($list,$position);
?>
The Result: a,b,d,e,f,g. The 'c' which was in the third position has noe been removed!

To use the ListDeleteAt function with a custom delimiter:

<php
$list = "12345";

$position = 2;
echo ListDeleteAt($list,$position);
?>

The Result: '1345'. The '2' which was in the second position has noe been removed!

xml to array

Here is the function which convert xml data to respective array.

function xmlToArray($xml,$ns=null){
$a = array();
for($xml->rewind(); $xml->valid(); $xml->next()) {
$key = $xml->key();
if(!isset($a[$key])) { $a[$key] = array(); $i=0; }
else $i = count($a[$key]);
$simple = true;
foreach($xml->current()->attributes() as $k=>$v) {
$a[$key][$i][$k]=(string)$v;
$simple = false;
}
if($ns) foreach($ns as $nid=>$name) {
foreach($xml->current()->attributes($name) as $k=>$v) {
$a[$key][$i][$nid.':'.$k]=(string)$v;
$simple = false;
}
}
if($xml->hasChildren()) {
if($simple) $a[$key][$i] = xmlToArray($xml->current(), $ns);
else $a[$key][$i]['content'] = xmlToArray($xml->current(), $ns);
} else {
if($simple) $a[$key][$i] = strval($xml->current());
else $a[$key][$i]['content'] = strval($xml->current());
}
$i++;
}
return $a;
}
This function can be used as follows.
$xml = new SimpleXmlIterator('./a.xml', null, true);
$namespaces = $xml->getNamespaces(true);
$arr = xmlToArray($xml,$namespaces);

Testing web Application


Nowadays lot's of effort is gone for testing and quality assurance of the web application which can be minimized by using web based testing tools available on the web.

There are lot's of Ad-ons available for mozila firfox for different kind of the testing which Includes such as iMacros for Firefox, WASP, Fireshot, Window Resizer, Selenium IDE, Web Developer, SwitchProxy, IE Tab, Molybdenum, HackBar, and many more.

Selenium IDE
is an integrated development environment for Selenium tests.allows you to record, edit, and debug tests.You can choose to use its recording capability, or you may edit your scripts by hand.

Web Developer The Web Developer extension adds a menu and a toolbar to the browser with various web developer tools. It is designed for Firefox, Flock and Seamonkey, and will run on any platform that these browsers support including Windows, Mac OS X and Linux.

Hackbar allow you to test your web pages against sql injections, XSS holes and site security.It is not used for executing standard exploits.

These are few ad-ons which I use and It help me as a developer/tester to test website more rapidly.