Archive for July 2013

Form elements added by jquery not getting on the submit page - Fixation

I had a form and some of the form elements are adding to it dynamically by jquery. But when submitting the form I am not getting the fields added by jquery in $_POST or $_GET.

After a long searching I found that, it was due to the form element was inside some nested div. I placed the form start before the div start tag and form end after the div end tag. Now the problem solved.

So please check the form tag is correctly placed before any table or div tags.

Sessions

Sessions are used to store data on server and retrieve it for a user while they travel through a series of pages, or page iterations, on your site. They are same as cookie , the only difference is that they are stored at server while cookie stored at client machine.

To start session
<?php
    session_start();
    $_SESSION['variable1'] = 'value1';
?>

To retrieve variable on other script/page use
<?php
    session_start();
    echo $_SESSION['variable1'];
?>

$_get() in php

<?php

if(isset($_GET['name'])&&isset($_GET['age']))
{
  $name=$_GET['name'];
  $age=$_GET['age'];
  if(!empty($name)&&!empty($age))
  {
   echo '<center>you filled both fields<br><br></center>';
  }
  else
  {
   echo '<center>you not filled both fields<br><br></center>';
  }

}

?>
<center><form action="get.php" method="get">

               NAME :<input type="text" name="name">

               AGE  :<input type="text" name="age">

                <input type="submit" value="submit">
</form></center>

output :

after filled all fields you clicked on submit button just vies on address bar
it displays you entered data

Php Error Control Operators

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable $php_errormsg. This variable will be overwritten on each error, so check early if you want to use it.

<?php

/* Intentional file error */

$my_file = @file ('non_existent_file') or

die ("Failed opening file: error was '$php_errormsg'");

// this works for any expression, not just functions:

$value = @$cache[$key];

// will not issue a notice if the index $key doesn't exist.

?>


Note: The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include() calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.

Warning

Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.

Control structures in Php: return

If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file.
If called from the global scope, then execution of the current script file is ended. If the current script file was include()ed or require()ed, then control is passed back to the calling file. Furthermore, if the current script file was include()ed, then the value given to return() will be returned as the value of the include() call. If return() is called from within the main script file, then script execution ends. If the current script file was named by the auto_prepend_file or auto_append_file configuration options in php.ini, then that script file's execution is ended.

Note: Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case.

Note: You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a).

User logs out in php Penny Auction

I am a web developer.

One of my clients bought the phpPennyAuction from phpPennyAuction.com

Man... it has been such a problem. The support sucks. The client paid $250 for a payment gateway which was still not functioning 6 months later.

They are very prompt on pre-sales.
Once their money is paid, they basically even stop answering mails.

Here are some of the things that i fixed for my client:

- the system logs the user out whenever he visits the payment gateway. In case of my client it is iPay88, a Malaysian gateway. I fixed this problem. I understand that there are many others that might have same problem.

- The system has a lot of things as plugins. Ofcourse if the support would work, you could use them.

- I also re-designed the site and created a lot of small modules.


So if you are facing problems with php Penny Auction, give me a shout. Maybe I can help.

Cheers
TeaCii
http://www.hybridCommerce.my

Security


1. Avoid using uninitialized variable. 
If the register_globals(php.ini) is turned on , the uninitialized variable can cause security breach.

Example:


Following code is used to recognize admin in 'test.php' script.

<?php
    if($user==0) {
          $admin = true;
    }
?>

If register_globals is on, the url http://www.testdomain.com/test.php?user=0 will declare $user as a global variable with no code required and thus provide admin status.




2. Never trust user data

Example:

<?php
    readfile($_POST['filename']);
?>

In this case if you really want the user to be able to specify a filename that gets used in any of PHP's file functions, do something like this:

<?php
    $doc_root = $_SERVER['DOCUMENT_ROOT'];
    $filename = realpath($filename);
    readfile($doc_root.$filename);
?>

You may also want to strip out any path and only take the filename component. An easy way to do that is to use the basename() function. Or perhaps check the extension of the file. You can get the extension using this code:

<?php
$ext = substr($str,strrpos($str,'.'));
?>


3. Make sure users can't pass in arguments that executes other system calls, make sure that the argument itself is ok and only accesses data you want the users to have access to.

Example:

<?php
system("ls $dir");
?>

In this example you want to make sure that the user can't pass in $dir set to something like: ".;cat/etc/passwd". The remedy is to use escapeshellarg() which places the argument inside single quotes and escapes any single quote characters in the string.

<?php
$dir=escapeshellarg($dir);
system("ls $dir");
?>


4. Place included files outside of the DOCUMENT_ROOT directory.

Many users place code in multiple files and include these files:
<?php
require 'functions.inc';
?>

Or perhaps

<?php
require 'functions.php';
?>

Both of these can be problematic if the included file is accessible somewhere under the DOCUMENT_ROOT directory. The best solution is to place these files outside of the DOCUMENT_ROOT directory where they are not accessible directly. You can add this external directory to your include_path configuration setting. Another option is to reject any direct requests for these files in your Apache configuration. You can use a rule like this in your "httpd.conf" file:

<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>

PHP File Uploading




A PHP script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script.
Information in the phpinfo.php page describes the temporary directory that is used for file uploads as upload_tmp_dir and the maximum permitted size of files that can be uploaded is stated as upload_max_filesize. These parameters are set into PHP configuration file php.ini
The process of uploading a file follows these steps
  • The user opens the page containing a HTML form featuring a text files, a browse button and a submit button.
  • The user clicks the browse button and selects a file to upload from the local PC.
  • The full path to the selected file appears in the text filed then the user clicks the submit button.
  • The selected file is sent to the temporary directory on the server.
  • The PHP script that was specified as the form handler in the form's action attribute checks that the file has arrived and then copies the file into an intended directory.
  • The PHP script confirms the success to the user.
As usual when writing files it is necessary for both temporary and final locations to have permissions set that enable file writing. If either is set to be read-only then process will fail.
An uploaded file could be a text file or image file or any document.
Creating an upload form:
The following HTM code below creates an uploader form. This form is having method attribute set to post and enctype attribute is set to multipart/form-data
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="/php/file_uploader.php" method="post"
                        enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

Creating an upload script:
There is one global PHP variable called $_FILES. This variable is an associate double dimension array and keeps all the information related to uploaded file. So if the value assigned to the input's name attribute in uploading form was file, then PHP would create following five variables:
  • $_FILES['file']['tmp_name']- the uploaded file in the temporary directory on the web server.
  • $_FILES['file']['name'] - the actual name of the uploaded file.
  • $_FILES['file']['size'] - the size in bytes of the uploaded file.
  • $_FILES['file']['type'] - the MIME type of the uploaded file.
  • $_FILES['file']['error'] - the error code associated with this file upload.
The following example below attempts to copy a file uploaded by the HTML Form listed in previous section page to /var/www/html directory which is document root of your PHP server and it will display all the file's detail upon completion. Please note that if you are going to display uploaded file then don't try with binary files like images or word document.
Here is the code of uploader.php script which will take care of uploading a file.
<?php
if( $_FILES['file']['name'] != "" )
{
   copy( $_FILES['file']['name'], "/var/www/html" ) or
           die( "Could not copy file!");
}
else
{
    die("No file specified!");
}
?>
<html>
<head>
<title>Uploading Complete</title>
</head>
<body>
<h2>Uploaded File Info:</h2>
<ul>
<li>Sent file: <?php echo $_FILES['file']['name'];  ?>
<li>File size: <?php echo $_FILES['file']['size'];  ?> bytes
<li>File type: <?php echo $_FILES['file']['type'];  ?>
</ul>
</body>
</html>
When you will upload a file using upload form and upload script, it will display following result:
Uploaded File Info:

·         Sent file: uploadedfile.txt

·         File size: 2003 bytes

·         File type: image/jpg


Assignment #7: User registration

Description: A user registration page is created for the user to create his account on this web-site.


1) /includes/createSelect.php : To show the locations in drop-down list.

2) registerSubmit.php: It receives form data from login.php to verify auth of user. User's DB is checked to verify the user ID.

3) register.php: It is the main page for the user to registrate. A form's field is extracted from createSelect.php.

4) feedback.php.php: For successful or unsuccessful login, users are forwarded to this page and error messages are generated for unsuccessful registration.

Learnt: Putting all form-content inside a include file for tidiness. Using session again to check the existence of the user. Simple javascript to check to form is well filled before sending it back to the server.

The History of PHP

Rasmus Lerdorf— software engineer, Apache team member, and international man of mystery — is the creator and original driving force behind PHP. The first part of PHP was devel-oped for his personal use in late 1994. This was a CGI wrapper that helped him keep track of people who looked at his personal site. The next year, he put together a package called the Personal Home Page Tools (a.k.a. The PHP Construction Kit) in response to demand from users who had stumbled into his work by chance or word of mouth. Version 2 was soon released under the title PHP/FI and included the Form Interpreter, a tool for parsing SQL queries.

By the middle of 1997, PHP was being used on approximately 50,000 sites worldwide. It was clearly becoming too big for any single person to handle, even someone as focused and energetic as Rasmus. A small core development team now runs the project on the open source “benevolent junta” model, with contributions from developers and users around the world.

Zeev Suraski and Andi Gutmans, the two Israeli programmers who developed the PHP3 and

PHP4 parsers, have also generalized and extended their work under the rubric of Zend.com

The fourth quarter of 1998 initiated a period of explosive growth for PHP, as all open source technologies enjoyed massive publicity. In October 1998, according to the best guess, just over 100,000 unique domains used PHP in some way. Just over a year later, PHP broke the one-million domain mark. When we wrote the first edition of this book in the first half of 2000, the number had increased to about two million domains. As we write this, approximately 15 million public Web servers (in the software sense, not the hardware sense) have PHP installed on them.

Public PHP deployments run the gamut from mass-market sites such as Excite Webmail and the Indianapolis 500 Web site, which serve up millions of pageviews per day, through “massniche” sites such as Sourceforge.net and Epinions.com, which tend to have higher functionality needs and hundreds of thousands of users, to e-commerce and brochureware sites such as The Bookstore at Harvard.com and Sade.com (Web home of the British singer), which must be visually attractive and easy to update. There are also PHP-enabled parts of sites, such as the forums on the Internet Movie Database (imdb.com); and a large installed base of nonpublic PHP deployments, such as LDAP directories (MCI WorldCom built one with over 100,000 entries) and trouble-ticket tracking systems.

In its newest incarnation, PHP5 strives to deliver something many users have been clamoring for over the past few years: much improved object-oriented programming (OOP) functionality. PHP has long nodded to the object programming model with functions that allow object programmers to pull out results and information in a way familiar to them. These efforts still fell short of the ideal for many programmers, however, and efforts to force PHP to build in fully object-oriented systems often yielded unintended results and hurt performance. PHP5’s newly rebuilt object model brings PHP more in line with other object-oriented languages such as Java and C++, offering support for features such as overloading, interfaces, private member variables and methods, and other standard OOP constructions.

With the crash of the dot-com bubble, PHP is poised to be used on more sites than ever.

Demand for Web-delivered functionality has decreased very little, and emerging technological standards continue to pop up all the time, but available funding for hardware, licenses, and especially headcount has drastically decreased. In the post-crash Web world, PHP’s shallow learning curve, quick implementation of new functionality, and low cost of deployment are hard arguments to beat.


How to reset Mysql root pasword on Windows


  1. Log on to your system as Administrator.

  2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
    If your server is not running as a service, you may need to use the Task Manager to force it to stop.

  3. Create a text file containing the following statements. Replace the password with the password that you want to use.
    UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
    WHERE User='root';
    FLUSH PRIVILEGES;

  4. Save the file. For this example, the file will be named C:\mysql-init.txt.

  5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.


  6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):
C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt


Operation complete ;)

Check here for Mysql documentation.

PHP foreach statement

PHP foreach statement works on PHP array by which we can reach every elements of an array. For example, we have an array like $array(10,20,30,40), we want to print each element of that array. In this kind of case that means in PHP array we use PHP foreach statement. Now take a look at the structure of PHP foreach statement.
foreach($array as $value)

{

code to be executed;

}
In the foreach statement at first we use the actual array and then we use a temporary variable which is used to store the array elements.

foreach statement example

Now I am trying to provide an example. Think that we have an array that contains number 1,2,3,4,5 . So now try to print each array value using PHP.
<?php
$number=array(1,2,3,4,5);
foreach($number as $value )
{
    echo $value;
    }
?>
In the above code we just print the each value of this array. Now we try to print something based on condition. So now take a look at the example.
<?php
$number=array(1,2,3,4,5);
foreach($number as $value )
{
    if($value==3)
    echo $value;
    else
    echo $value;
    }
?>

Php Tips

You can write less code for same result and It is more understandable.


$var = $var + 1; // Add 1 to $var
$var ++; // Gives same result


Also work with this;

$var = $var - 1; // Sub 1 to $var
$var --; // Gives same result



$var = "It"
$var = $var + " can be..."; // Result : It can be...
$var .= " can be..."; // Result : It can be...


Shortcut for If Else;

if($var != "page"){
$out ++; // Add 1 to $out
}

if($var != "page") $out ++; // Gives same result (Add 1 to $out)


Much more is coming soon. (:

While Loop in Php

While loop saves your time. If you want to print all mysql rows, all value in array, you can use While loop.

Simple Example;


$i = 0;
while ( $i <= 10 ) {
echo "Number: " . $i;
$i++;
}


First; we defined $i as '0'. After we started the While loop statement. If $i number is less or equal to '10', process will continue. If $i number equals to '10', process will end and PHP will continue to generate page.

Here is other syntax.

$i = 1;
while ($i <= 10):
echo $i;
$i++;
endwhile;


While, Foreach, For Next loop statement are save your time to listing any mysql result.

Reasons to Love PHP and MySQL

There are ever so many reasons to love PHP and MySQL. Let us count a few.

Cost

PHP costs you nothing. Zip, zilch, nada, not one red cent. Nothing up front, nothing over the lifetime of the application, nothing when it’s over. Did we mention that the Apache/PHP/MySQL combo runs great on cheap, low-end hardware that you couldn’t even think about for IIS/ASP/SQL Server?

MySQL is a slightly different animal in its licensing terms. Before you groan at the concept of actually using commercial software, consider that although MySQL is open-source licensed for many uses, it is not and has never been primarily community-developed software. MySQL AB is a commercial entity with necessarily commercial interests. Unlike typical open source projects, where developers often have regular full-time (and paying) day jobs in addition to their freely given open source efforts, the MySQL developers derive their primary income from the project. There are still many circumstances in which MySQL can be used for free (basically anything nonredistributive, which covers most PHP-based projects), but if you make money developing solutions that use MySQL, consider buying a license or a support

contract. It’s still infinitely more reasonable than just about any software license you will ever pay for.

For purposes of comparison, Table 1-1 shows some current retail figures for similar products in the United States. All prices quoted are for a single-processor public Web server with the most common matching database and development tool; $0 means a no-cost alternative is a common real-world choice.

Comparative Out-of-Pocket Costs

ASP/SQL ColdFusion

Item Server MX/SQL Server JSP/Oracle PHP/MySQL

Development tool $0–2499 $599 $0–~2000 $0–249

Server $999 $2298 $0–~35,000 $0

RDBMS $4999 $4999 $15,000 $0–220

Open source software: don’t fear the cheaper

But as the bard so pithily observed, we are living in a material world —where we’ve internalized maxims such as, “You get what you pay for,” “There’s no such thing as a free lunch,” and “Things that sound too good to be true usually are.” You (or your boss) may, therefore, have some lingering doubts about the quality and viability of no-cost software. It probably doesn’t help that until recently software that didn’t cost money — formerly called freeware , shareware, or free software — was generally thought to fall into one of three categories:

Programs filling small, uncommercial niches

Programs performing grungy, low-level jobs

Programs for people with bizarre socio-political issues

It’s time to update some stereotypes once and for all. We are clearly in the middle of a sea change in the business of software. Much (if not most) major consumer software is distributed without cost today; e-mail clients, Web browsers, games, and even full-service office suites are all being given away as fast as their makers can whip up Web versions or set up

FTP servers. Consumer software is increasingly seen as a loss-leader, the flower that attracts the pollinating honeybee — in other words, a way to sell more server hardware, operating systems, connectivity, advertising, optional widgets, or stock shares. The full retail price of a piece of software, therefore, is no longer a reliable gauge of its quality or the eccentricity-level of its user.

On the server side, open source products have come on even stronger. Not only do they

compete with the best commercial stuff; in many cases there’s a feeling that they far exceed the competition. Don’t take our word for it! Ask IBM, any hardware manufacturer, NASA, Amazon.com, Rockpointe Broadcasting, Ernie Ball Corporation, the Queen of England, or the Mexican school system. If your boss still needs to be convinced, further ammunition is available at www.opensource.org and www.fsf.org.

Get result from database using a function SafDBFunc

<?
//Get result from database using a function SafDBFunc
//From following function you will get an output staff name
//To get the staff name you need to pass some veribles like table name ($tablename) and databse conncetion ($db)
//and also the staff number ($staffid), it will go inside the function and open the databse in given table for the record
function TakeStaffNameSafDBFunc($tablename,$db,$staffid){
$sql = "SELECT * FROM $tablename where staffid='$staffid'";
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
if (
mysql_num_rows($result_a)) {
$data = mysql_fetch_object($result);
$fldStaffName = $data->fldStaffName;
}
return
$fldStaffName;
}
?>

Javascript for checking Caps Lock is ON or OFF

function checkCapsLock( e ) {
var myKeyCode=0;
var myShiftKey=false;
var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

// Internet Explorer 4+
if ( document.all ) {
myKeyCode=e.keyCode;
myShiftKey=e.shiftKey;

// Netscape 4
} else if ( document.layers ) {
myKeyCode=e.which;
myShiftKey=( myKeyCode == 16 ) ? true : false;

// Netscape 6
} else if ( document.getElementById ) {
myKeyCode=e.which;
myShiftKey=( myKeyCode == 16 ) ? true : false;

}

// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
alert( myMsg );

// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
alert( myMsg );

}
}

INPUT TYPE="Password" NAME="Password" SIZE=16 MAXLENGTH=16 onKeyPress="checkCapsLock( event )"

concatenation in php

<?php

$name='php';
$version='5.4';
$use='for web development';

echo  'hai the ';
echo   ' ';
echo  $name;
echo   ' ';
echo  $version;
echo   ' ';
echo  $use;

 // for new line

echo '<br>';


//      "." use for concatenation

echo 'hai the '.$name.' '.$version.' '.$use;
?>


output :

hai the php 5.4 for web development
hai the php 5.4 for web development

Php Comparison Operators

Comparison operators, as their name implies, allow you to compare two values. You may also be interested in viewing the type comparison tables, as they show examples of various type related comparisons.

Comparison Operators

Example

Name

Result

$a == $b

Equal

TRUE if $a is equal to $b.

$a === $b

Identical

TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

$a != $b

Not equal

TRUE if $a is not equal to $b.

$a <> $b

Not equal

TRUE if $a is not equal to $b.

$a !== $b

Not identical

TRUE if $a is not equal to $b, or they are not of the same type. (introduced in PHP 4)

$a < $b

Less than

TRUE if $a is strictly less than $b.

$a > $b

Greater than

TRUE if $a is strictly greater than $b.

$a <= $b

Less than or equal to

TRUE if $a is less than or equal to $b.

$a >= $b

Greater than or equal to

TRUE if $a is greater than or equal to $b.

If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement.

<?php
var_dump(0 == "a"); // 0 == 0 -> true
var_dump("1" == "01"); // 1 == 1 -> true
var_dump("1" == "1e0"); // 1 == 1 -> true

switch ("a") {
case 0:
echo "0";
break;
case "a": // never reached because "a" is already matched with 0
echo "a";
break;
}
?>

For various types, comparison is done according to the following table (in order).

Comparison with Various Types

Type of Operand 1

Type of Operand 2

Result

null or string

String

Convert NULL to "", numerical or lexical comparison

bool or null

anything

Convert to bool, FALSE < TRUE

object

object

Built-in classes can define its own comparison, different classes are uncomparable, same class - compare properties the same way as arrays (PHP 4), PHP 5 has its own explanation

string, resource or number

string, resource or number

Translate strings and resources to numbers, usual math

array

array

Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then arrays are uncomparable, otherwise - compare value by value (see following example)

array

anything

array is always greater

object

anything

object is always greater

Example Transcription of standard array comparison

<?php
// Arrays are compared like this with standard comparison operators
function standard_array_compare($op1, $op2)
{
if (count($op1) < count($op2)) {
return -1; // $op1 < $op2
} elseif (count($op1) > count($op2)) {
return 1; // $op1 > $op2
}
foreach ($op1 as $key => $val) {
if (!array_key_exists($key, $op2)) {
return null; // uncomparable
} elseif ($val < $op2[$key]) {
return -1;
} elseif ($val > $op2[$key]) {
return 1;
}
}
return 0; // $op1 == $op2
}
?>

Ternary Operator

Another conditional operator is the "?:" (or ternary) operator.

Example Assigning a default value

<?php
// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

// The above is identical to this if/else statement
if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}

?>


The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.

Note: Please note that the ternary operator is a statement, and that it doesn't evaluate to a variable, but to the result of a statement. This is important to know if you want to return a variable by reference. The statement return $var == 42 ? $a : $b; in a return-by-reference function will therefore not work and a warning is issued in later PHP versions.

Note: Is is recommended that you avoid "stacking" ternary expressions. PHP's behaviour when using more than one ternary operator within a single statement is non-obvious:

Example Non-obvious Ternary Behaviour

<?php
// on first glance, the following appears to output 'true'
echo (true?'true':false?'t':'f');

// however, the actual output of the above is 't'
// this is because ternary expressions are evaluated from left to right

// the following is a more obvious version of the same code as above
echo ((true ? 'true' : 'false') ? 't' : 'f');

// here, you can see that the first expression is evaluated to 'true', which
// in turn evaluates to (bool)true, thus returning the true branch of the
// second ternary expression.
?>