Archive for September 2012

PHP continue statement

PHP continue statement and break statement are identical but the only difference is PHP continue statement just skip the current iteration and continue execute other iteration inside loop. We can use continue statement in PHP iteration statement such as for loop, while loop and do-while loop. 

We can define PHP continue statement by using if statement such as if(condition) continue;  If the condition is true then the continue statement is executed.  Now we consider an example to understand the PHP continue statement.

PHP continue statement example:

<?php

for($count=0; $count<=10; $count++)

{

if($count==5)

continue;

echo $count;

}
In this example after if condition we use continue statement. So this program not print 5 because for continue statement. The output look like this where 5 is missing
1234678910

assignment operators in php



                            assignment operators in php     :      = , += , -= , *= , /= , .= , %=

<?php

$num1=10;
$num2=20;
echo ('<br>'. $num1." " .$num2);
?>


output :10 20




<?php
$num1=10;
$num2=20;
echo ('<br>'.$num2+=$num1);
?>


output :
30 





<?php


$num1=10;
$num2=20;
echo ('<br>'.$num2-=$num1
);?>


output :
10



<?php


$num1=10;
$num2=20;
echo ('<br>'.$num2*=$num1);
?>


output :
200





<?php


$num1=10;
$num2=20;


echo ('<br>'.$num2/=$num1);?>

output :
2



<?php
$num1=10;
$num2=20;
echo ('<br>'.$num2.=$num1);?>


output :
2010




<?php

$num1=10;
$num2=20;
echo ('<br>'.$num2%=$num1);

?>

output :
0








How to install propel on Ubuntu with pear

First install php-pear and php5-xsl, if you don't already have.

sudo apt-get install php5-xsl php-pear

Than you should install phing
sudo pear channel-discover pear.phing.info
sudo pear install phing/phing

Now you can install propel
sudo pear channel-discover pear.propelorm.org
sudo pear install -a propel/propel_generator
sudo pear install -a propel/propel_runtime

Also you can install Log
sudo pear install -a Log

Now you can use propel-gen in the console.
propel files at /usr/share/php/propel

Data Types in PHP

PHP supports eight primitive types.

Four scalar types:

boolean

integer

float (floating-point number, aka 'double')

string

Two compound types:

array

object

And finally two special types:

resource

NULL

This page also introduces some pseudo-types for readability reasons:

mixed

number

callback

And the pseudo-variable $....

You may also find some references to the type "double". Consider double the same as float, the two names exist only for historic reasons.

The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used.

Note: If you want to check out the type and value of a certain expression, use var_dump().

If you simply want a human-readable representation of the type for debugging, use gettype(). To check for a certain type, do not use gettype(), but use the is_type functions. Some examples:

$a_bool = TRUE; // a boolean

$a_str = "foo"; // a string

$a_str2 = 'foo'; // a string

$an_int = 12; // an integer

echo gettype($a_bool); // prints out: boolean

echo gettype($a_str); // prints out: string

// If this is an integer, increment it by four

if (is_int($an_int)) {

$an_int += 4;

}

// If $bool is a string, print it out

// (does not print out anything)

if (is_string($a_bool)) {

echo "String: $a_bool";

}

?>

If you would like to force a variable to be converted to a certain type, you may either cast the variable or use the settype() function on it.

Hire Php Web Developers Designers India

Hire Dedicated Php Web Developers Website Designers Programmers in India to design customized website application as per your business needs.

This Php Web Development Service Providers Web Developers and Website Designers and Prorammers are Available to Hire as Dedicated Staff.

Hire Php Website Developer from India

Hiring Php Web Developers any corporate company can easily develop their custom web application as per their complex business requirements.

Thanks & Regards

WeTheDevelopers - Php Web Development Company India

www.WeTheDevelopers.com

PHP Security

Now-a-days web security has been a major concern.During development, when the code is being written, it is important to consider illegitimate uses of your application. Often, the focus is on making the application work as intended, and while this is necessary to deliver a properly functioning application, it does nothing to help make the application secure. fact that you are here is evidence that you care about security,

Since PHP is a growing language being used for the web development,It's very important to discuss about PHP security.

Input flaws
most common PHP security flaws is the unvalidated input error. User-provided data simply cannot be trusted and should be validated properly.

register_globals = OFF. The register_globals directive is disabled by default in PHP versions 4.2.0 and greater.Enabling register_globals may cause a security risk.
A common example to explain the problem is as follows.
this example that illustrates how register_globals can be problematic is the following use of include with a dynamic path:


With register_globals enabled, this page can be requested with ?path=http%3A%2F%2Fevil.example.org%2F%3F in the query string in order to equate this example to the following:




Avoid using $_REQUEST[] since as per GPC rule $_GET has higher priorities than $_POST, So $_POST variables may be overwritten.

Always validate input data against maxlength in PHP.you can use array and for each to do this.
50);
foreach($max as $key=>$val)
{
if(strlen($_POST[$key])>$val)
{
//display maxlength error
}
}
?>



Assignment #5

File created:
1)item.php (time spent: 1hr 20 mins)
To view each single item within the database.

2)categories.php (time spent: 1hr 30 mins)
To view all the items, can be sorted according to different categories.

3)mysql_content.sql (time spent: 1/2 hr)
Define the DB schema.
Learnt: To design and use mysql schema and sort the Data by categories.

The while Statement

The while Statement

The while statement is useful, when you want to loop a code until it's conditions are met.
Syntax :
while (condition)
code ....


Example :
");}
echo "Value is ". $val .". condition not met!
";
$val++;
}
?>
Output of this code is :

Value is 0. condition not met!

Value is 1. condition not met!
Value is 2. condition not met!
Value is 3. condition not met!
Value is 4. condition not met!
Value is 5. condition not met!
Value is 6. condition not met!
Value is 7. condition not met!
Value is 8. condition not met!
Value is 9. condition not met!
Value is 10. condition met!

Above code loops until the value is 10.

All free PHP video tutorials from start to finish

From this free PHP video tutorial lesson you can watch all essential part of PHP. In this part I orderly organize all free PHP video tutorials. So guys start your PHP journey with us. You can watch all PHP video tutorials from youtube just clicking skip add.

PHP basic free video Tutorials index

Introduction to PHP , Installing XAMPP Part 1 , Installing XAMPP Part 2
Creating Your First PHP File , Writing Your First PHP File , The phpinfo Function

PHP Indentation , PHP echo function , PHP print function , Embedding PHP Inside HTML
PHP comments , Reporting error in PHP , PHP Variables , Concatenation with PHP

PHP if......else Statement , Assignment Operators  , PHP Comparison Operators
Arithmetic Operators , Logical Operators , For Loop in PHP , While Loop in PHP
PHP do while Loop , PHP switch Statement , for each Statement

PHP die and exit Functions , PHP Functions basic , Functions with Arguments ,
Functions with a Return Value , PHP Global Variables and Functions
PHP String Functions Part-1 , PHP String Functions Part 2, PHP String Functions Part 3
PHP String Functions Part 4

Introduction to PHP Arrays , Associative Arrays , Multi-dimensional Arrays

PHP String Functions: String Length , String Position Part 1 , String Position Part 2
Replacing Predefined Part of a String , Expression Matching in PHP

PHP advanced free Video Tutorials index



section/tmpl/blog_item.php

here is custom code .. please find

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


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


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')) : ?>


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

checking if an element is in array or not using in_array() in php

element_in_array.php :

<?php
// Checking if an Element Is in Array or not

$num=array(1,2,3,4,5,6,7,8,9,10);

$element=$_POST['element'];

if (in_array($element, $num)) {
echo 'element found';
}
else
{
echo 'element not found';
}


?>

============================================================
element_in_array_index.php :

<center><b>here checks data is in array or not</b><br><br>
<center><form action="element_in_array.php" method="POST">
<input type="textbox" name="element">
<input type="submit" name="submit">
</form>

============================================================
input :

1) give the array values in text box

2)  click in button

ex :

array :$num=array(1,2,3,4,5,6,7,8,9,10);

here 0-9 array indexes
and
1-10 array values
 
============================================================
output :

1) element found

2) element not found

PHP Web Concepts



This session demonstrates how PHP can provide dynamic content according to browser type, randomly generated numbers or User Input. It also demonstrated how the client browser can be redirected.
Identifying Browser & Platform
PHP creates some useful environment variables that can be seen in the phpinfo.php page that was used to setup the PHP environment.
One of the environment variables set by PHP is HTTP_USER_AGENT which identifies the user's browser and operating system.
PHP provides a function getenv() to access the value of all the environment variables. The information contained in the HTTP_USER_AGENT environment variable can be used to create dynamic content appropriate to the browser.
Following example demonstrates how you can identify a client browser and operating system.
NOTE: The function preg_match () is discussed in PHP Regular expression session.
<html>
<body>
<?php
   $viewer = getenv( "HTTP_USER_AGENT" );
   $browser = "An unidentified browser";
   if( preg_match( "/MSIE/i", "$viewer" ) )
   {
      $browser = "Internet Explorer";
   }
   else if(  preg_match( "/Netscape/i", "$viewer" ) )
   {
      $browser = "Netscape";
   }
   else if(  preg_match( "/Mozilla/i", "$viewer" ) )
   {
      $browser = "Mozilla";
   }
   $platform = "An unidentified OS!";
   if( preg_match( "/Windows/i", "$viewer" ) )
   {
      $platform = "Windows!";
   }
   else if ( preg_match( "/Linux/i", "$viewer" ) )
   {
      $platform = "Linux!";
   }
   echo("You are using $browser on $platform");
?>
</body>
</html>
This is producing following result on my machine. This result may be different for your computer depending on what you are using.
You are using Mozilla! on Windows!
Display Images Randomly
The PHP rand() function is used to generate a random number. i This function can generate numbers with-in a given range. The random number generator should be seeded to prevent a regular pattern of numbers being generated. This is achieved using the srand() function that specifies the seed number as its argument.
Following example demonstrates how you can display different image each time out of four images:
<html>
<body>
<?php
  srand( microtime() * 1000000 );
  $num = rand( 1, 4 );
  
  switch( $num )
  {
  case 1: $image_file = "/home/images/alfa.jpg";
          break;
  case 2: $image_file = "/home/images/ferrari.jpg";
          break;
  case 3: $image_file = "/home/images/jaguar.jpg";
          break;
  case 4: $image_file = "/home/images/porsche.jpg";
          break;
  }
  echo "Random Image : <img src=$image_file />";
?>
</body>
</html>
Using HTML Forms
The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.
Try out following example by putting the source code in test.php script.
<?php
  if( $_POST["name"] || $_POST["age"] )
  {
     echo "Welcome ". $_POST['name']. "<br />";
     echo "You are ". $_POST['age']. " years old.";
     exit();
  }
?>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="POST">
  Name: <input type="text" name="name" />
  Age: <input type="text" name="age" />
  <input type="submit" />
  </form>
</body>
</html>
  • The PHP default variable $_PHP_SELF is used for the PHP script name and when you click "submit" button then same PHP script will be called and will produce following result:
  • The method = "POST" is used to post user data to the server script. There are two methods of posting data to the server script which are discussed in PHP GET & POST chapter.
Browser Redirection
The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading.
The target is specified by the Location: header as the argument to the header()function. After calling this function the exit() function can be used to halt parsing of rest of the code.
Following example demonstrates how you can redirect a browser request to another web page. Try out this example by putting the source code in test.php script.
<?php
  if( $_POST["location"] )
  {
     $location = $_POST["location"];
     header( "Location:$location" );
     exit();
  }
?>
<html>
<body>
   <p>Choose a site to visit :</p>
   <form action="<?php $_PHP_SELF ?>" method="POST">
   <select name="location">
      <option value="http://w3c.org">
            World Wise Web Consortium
      </option>
      <option value="http://www.google.com">
            Google Search Page
      </option>
   </select>
   <input type="submit" />
   </form>
</body>
</html>
Displaying "File Download" Dialog Box
Sometime it is desired that you want to give option where a use will click a link and it will pop up a "File Download" box to the user in stead of displaying actual content. This is very easy and will be achived through HTTP header.
The HTTP header will be different from the actual header where we send Content-Typeas text/html\n\n. In this case content type will be application/octet-streamand actual file name will be concatenated alongwith it.
For example,if you want make a FileName file downloadable from a given link then its syntax will be as follows.
#!/usr/bin/perl

# HTTP Header
print "Content-Type:application/octet-stream; name=\"FileName\"\r\n";
print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n";

# Actual File Content
open( FILE, "<FileName" );
while(read(FILE, $buffer, 100) )
{
   print("$buffer");
}

php intruduction


Hypertext Pre-processor: What is PHP?


Hypertext Pre-processor  (PHPs) is a  server-side scripting language, and  server-sidescripts are special commands you must place in Web pages. Those commands are processed before the pages are sent from your Server to the Web browser of your visitor. A typical PHP files will content commands to be executed in the server in addition to the usual mixture of text and HTML (Hypertext Markup Language) tags.

When you type a URL in the Address box or click a link on a Web page, you're asking a Web server on a computer somewhere to send a file to the Web browser (sometimes called a "client") on your computer. If that file is a normal HTML file, it looks exactly the same when your Web browser receives it as it did before the Web server sent it. After receiving the file, your Web browser displays its contents as a combination of text, images, and sounds. In the case of PHP page, the process is similar, except there's an extra processing step that takes place just before the Web server sends the file. Before the Web server sends the HTML file to the Web browser, it runs all server-side scripts contained in the page. Some of these scripts display the current date, time, and other information. Others process information the user has just typed into a form, such as a page in the Web site's guestbook
To distinguish them from normal HTML pages, PHP files are usually given the ".php" extension.

What Can You Do with PHP?
There are many things you can do with PHP.
  • You can display date, time, and other information in different ways.
  • You can make a survey form and ask people who visit your site to fill it out, send emails, save the information to a file, etc
What Do PHP pages Look Like?

The appearance of an PHP page depends on who or what is viewing it. To the Web browser that receives it, an Active Server Page looks just like a normal HTML page. If a visitor to your Web site views the source code of an PHP page, that's what they see: a normal HTML page. However, the file located in the server  looks very different. In addition to text and HTML tags, you also see server-side scripts. This is what the PHP page looks like to the Web server before it is processed and sent in response to a request.

What Do PHP pages Look Like?

Server-side scripts look a lot like HTML tags. However, instead of starting and ending with lesser-than ( < ) and greater-than ( > ) brackets, they typically start with <?php or <? and will typically end with ?>. The <?php or <? are called anopening tags, and the ?> is called a closing tag. In between these tags are the server-side scripts. You can insert server-side scripts anywhere in your Web page--even inside HTML tags.

Do You Have to Be a Programmer to Understand Server-Side Scripting?

There's a lot you can do with server-side scripts without learning how to program. For this reason, much of the online Help for PHP is written for people who are familiar with HTML but aren't computer programmers.