Wednesday, July 15, 2015

basic php

php

$third = $first;
$third .=$second;
echo $third;  #appending the string to variable

echo strtolower($third);
echo strtoupper($third);
echo ucfirst($third);  #firs letter of the string is capital
echo ucwords($third);    #first letter of words are capital case

##looping
##

<?php
$count=0;


?>
#########url encoding   it is legacy
get request is saved in $_GET =associative array
urlencode is for get request only

alphanumeric,underscore and dash is unchanged
reserved chars become %+2digit hexadecimal
reserved chars are !@#$%^&*()?.,; etc  not <,>
space become +

#####rawurlencode
similar to urlencode
space become %20

Rawurlencode is more compatible generally

urlencode: use it to encode the query string
-Query string is part after the "?"
=Space are better encoded as "+"



rawurlencode:
use it on path ,portion comes before the "?"
space must be encoded as %20
(help ful for apache and filesystem to find the page filesystem)


htmlspecialchars($string1)

include() = Dont throw error if files is not found[continued script]
require() = Throws error if file is not found[script stopped]
include_once()

###cookies
cookies can store up to 4000 characters maximum to store
cookies are stored in client browser

#pros of session:-
more storage
smaller request sizes(only sessionid is sent instead of eg 4000 char cookie)
conceal datavalues, more secure and less hackable

#cons of session
-slower to access
-expire when browser is closed
-session files accumulate


mysql_fetch_row
-result are in standard array-key are integers

mysqli_fetch_assoc
-result are in associative array
-key are column names

mysqli_fetch_array
-result are in array or associative array
-mysql_num,mysql_assoc,mysql_both

Recommended is mysqli_fetch_assoc [easier]





$name1="test2";
$value1=25;
$expire1 = time() + (60*60*24*7); #1week
setcookie($name1,$value1,$expire1);
//setcookie ($nameofcookie,$valueofcookie,$expirydateofcookie)


$test = isset($_COOKIE["test"]) ? $_COOKIE["test"] : "";
## unset cookies

setcookie($name, null, time()-3600)

###########

mysqli_fetch_row
=results are in a standard array
=keys are integers

mysqli_fetch_assoc
=result are in an associative array
=keys are column names

mysqli_fetch_array
=result are in either or both types of arrays
=MYSQL_NUM,MYSQL_ASSOC,MYSQL_BOTH