php notes
1. since designed with unix systems in mind, most parts is case sensitive...especially the one related to variable
calling etx
2. the difference between get and post is well known but one of the main advantages of the post method is
it can be used to send greater amount of information to be sent to the server. THERE IS A PHYSICAL LIMIT TO THE
amount you can transmit as part of the URL ...which is what the get method does ...so post is preferred or the only
option in cases where there is the textarea control etc...
3. one disadvantage of the post method is the pages cannot be properly bookmarked wheras those pages with get can as
the query string etc are part of the URL
4. Aslo URL encoding is used in the case of post method to avoid ambiguities that might arise in complex data sending ...
5. Array indexes always start from 0
6. always make sure to use $_GET['quantity'] , $_POST['quantity'];; etc to get the variables ..likewise for the post ....this is not stated in the book
perhaps that might be because the book is written for somebody testing the codes usinf their own system as the server
7. $capital=$_GET['Question1']; always copy the variable values that you get from the GET AND POST methods to a local
varialble that you declare in that specific file => reduces error a lot
8. The syntax to read the values of a multiple list box which is declared as
is (use get/posr)
e.g.
$size1=$_GET['EngineSize'][0];
$size2=$_GET['EngineSize'][1];
$size3=$_GET['EngineSize'][2];
$size4=$_GET['EngineSize'][3];
9. $capital=$_GET['Question1'];
echo "you selected the answer: $capital "; (**)
echo $capital;
the above is exacly the same as
$capital=$_GET['Question1'];
echo "you selected the answer:".$capital; (*)
echo $capital;
see the differnce is in the fact that in the second(*) we are using string concatentaion...in fact the parser takes this and
first generates the same as in (**)
10. HIDDEN FORM FIELDS for persistence ->see after 21
11. see page 143 how to execute a malicious script through the input! interesting...also see how to stop
especially the HTMLSpecialChars function
12. See the dynamic creation of form elements and data capturing using array of textbox etc
echo ""; ....page 163
13. WHENEVER THERE IS A NEED REFERENCE ARRAYS ON PAGE 167 ...see that in PHP, no allocation etc by the user...immediately the engine
does it for you ...cool ...see the mentioned page...from page 167 to 189 a lot of array related stuff
14. In the php engine that I am using(.pa.msu.) there are some syntax differnces like
echo "
".$_GET["Child"][$Count] cannot be written as echo "
$_GET["Child[$Count]"]" as the book advocates.
15. in php, by value and by reference are there
example
function tax($salary)
{
$salary=$salary + ...
}
this is by value
function tax(& $salary) => this is by reference
{
$salary=$salary + ...
}
the trap when using by reference, just like c++ etc
e.g. echo (tax(2000)); => cannot be used for the by reference case
but rather use
$salary=2000;
echo (tax(&$salary));=>correct
16. Global and local variables
variables inside a function => local just like other languages
$GLOBALS["VariableName" ]=>This is to access the GLOBALS array ...
17. Using the static key word to retain the values of local vars
e.g. function number_hits()
{
static $number=0;
return $number = $number + 1;
}
in the above, the first time the function is called, $number is initialized with 0...aftre that the first sentence is not
executed thereby retaining the previous value and one being added everytime it is called ..
18. see nesting of functions ...though not that useful
function pension($Total)
{
function tax($Salary)
{
return $Salary-10;
}
$Posttax=tax($Total);
return tax($Total)-(($Posttax/100)*3);
}
$Total=2500;
echo (pension($Total));....actually when nesting PHP 4.0 outputs errors =>thus use nesting only for recusion...see page 216
e.g.
function recursion ($val)
{
if ($val<=1)
return 1;
else
return $val*recursion($val-1)
19. include files
include("text.txt")...it will include the file at that particular points...text or html=>parsed...
20. see handling and avoiding error chapter 225-259
21. for comments use //
------------------see the program for e-mail checking using regular expression...it is cool------------
Persistence
========================
1. do it urself persistence
using Hidden => until one decides to commit the data stored in these variables to disk, the information stored in them exists
only in the memory occupied by the Client's browser
....mostly used in continue...sign up etc multiple forms to pass info from 1->2->3...see page 263