lamp_training_session_7
DESCRIPTION
Presentaions of LAMP Training Conducted by T.Umapathi Anand and R.Kasturi from Southern Telecom Region, BSNL at RTTC Trivandrum.TRANSCRIPT
������
������������� ���� ������������� ���� ������������
�������������������������� ��
Server Side Scripting Language for Dynamic Web Page Development
Open Source
Supports Large Number of Databases
����������������
������������� ���� ������������� ���� ������������
It can work as Server Module or as Stand Alone CGI Script
Resembles C, C++ and Perl
HTTP Authentication
Cookies
Sessions
File Uploads
������������
������������� ���� ������������� ���� ������������
File Uploads
Remote File Handling
Persistent Database Connections
Command Line Interpretation
Portable Code
������������� ���� ������������� ���� ������������
�� ��� �� ��� ��� �� �
��������� � ��� ��� �� � � � � � � � �� � ��� �
�� �� � ��� � � � � � � � �� � � � � � � � � � �
������������������ ��������
�� � � � �
� � ��� � � � � �
������������� ���� ������������� ���� ������������
�� � � � ��� �����
������� �������������� �������
��������� � ��� ��� �� � � � � � � � �� � ��� �
�� �� � ��� � � � � � � � �� � � � � � � � � � �
������������������������� ������� �� ��������������������� � �� ! ����"#$%�%& '!#���������� ��
The Server Time Now 15:44:31
������������� ���� ������������� ���� ������������
�� � � � ��� �����
����������� ������������������ �������
��������� � ��� ��� �� � � � � � � � �� � ��� �
�� �� � ��� � � � � � � � �� � � � � � � � � � �
�����(�)������(*+,��-#�)���� .�
/�"(�)����0�# '1����2��������������� ����������������
Welcome Trainees����������� �� �
������������� ���� ������������� ���� ������������
����2��������������� �������������������� � ��(�)��������������2�3�
�� � � �� �� ��� � � � � ���� � � � � � � � � � �� � �� � � �� � � � ! � � " � ��� � � ! �� �� � � � �� # �� � � �� � �� � � �� �� �� � ��� � � � ���� � � � �
�� �����
������������� ���� ������������� ���� ������������
������������� ���� ������������� ���� ������������
������������++�4���5++�4���5
����� � ����� � ����������� � ������� ���������� ��������� ������ ����������������
����������6������� ����������6�������
�
7������&7������&
�8��������������������������������������8� �8 8� � ������ ����� ���
����� � ������� ���� ������������� ���� ������������
�8��������������������������������������8���
�8 8� � ������ ����� ������ � �������� ����� ���
��������������� ���� ������������� ���� ������������
��� ���!��� ���! �"# �"#����� ��)������� ��)��
4,,9:;� (�� ���<=:
��</�> (�� ��#++�� ������ �(�� ��?++�� ������2�
/��/>:< (�� ���@�A�
B9,;� (�� � AACDE�(�� ��,FG@;7:�
7����H��7����H���)���)��
��������������� ���� ������������� ���� ������������
;<<;$ (�� ��� �)"#)�H ! �� ! ��� '�(�� ��� �)"�� 9��HF !�E� ;����� ! I)�J9 ! ++ '�
,4K:7� (�� ������I)7��&&"'�
�����������������)���)��
<:�,=<7: (�� ���)&L�*LH� )"?&������8�� ����MC��M��2'�
�=99 (�� ���H���
�"�$������� �"�$�������,�� �����&,�� �����& �����(�����(�� �� �� ��������������)������)��"("(�� �� '�'�
(�� ��?�ENG2� �ENG ��</�>
(�� O� �D �EPQ /��:>:<
(�� ����QQ �ECP B9,;�
(�� ��(�� C�?R2 �ECPR ��</�>
��������������� ���� ������������� ���� ������������
��������������� ���� ������������� ���� ������������
%���&�#%���&�#
S� ��M��S� ��M�� S������)S������) <��&��<��&��
(�� S����
(�� P S����
(P�� /������ ��� �&�������H�� ��
(�� * S����
(*�� /������ ��� �&�����=��� &�� �
(�T S����
��������������� ���� ������������� ���� ������������
(�T S����
(��U /������ ;�7//�7�� �Q�V �E@�����������
(���& /������ ��������S� ��M��<:�:<S:6
��������������� ���� ������������� ���� ������������
'��#����#'��#����#
S� ��M��S� ��M�� S������)S������) <��&��<��&��
6�����"�� !�Q'� S����
6�����"�� E!2��W'''�2'� S����
S� ��ENG� /������ � �����)���F
6�����"#�� ! B;9�:' S����
6�����"E�� !�Q' /������ ��� �&������H�� ��
6�����"*�� *!�Q' S����
��������������� ���� ������������� ���� ������������
6�����"*�� *!�Q' S����
6�����"#�� ��� !PQ' /������ �����������&����;������
6�����"**9/�:**!��<=:' /������ I�����7��&����<:�:<S:6
��������������� ���� ������������� ���� ������������
( "���#( "���#
; ��������; ��������,�� ��� &,�� ��� &
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
U � ����� ��� ������� ����������
O ������� �� �������� ���������������
U ���������� ��� ����� �� !��� � � ������������
8 "������������ ��� ����#��� $������������������
� !�%���� ��� ����&���
��������������� ���� ������������� ���� ������������
� !�%���� ��� ����&��� '���� ����������%�� �������
R "������ ��� ����(��� ) ��� ����������%�� �������
( "���#( "���#
;&&�������;&&�������,�� ��� &,�� ��� &
,�� ��� ,�� ��� :F�����:F����� <�&H��<�&H��
� ��� ��� ����������� ���� �*��� ������
O� ��� ��� +��%�� �������� ��������
U� ��� ��� +��%�� �������� ����� ��
8� ��# ��� +��%�� �������� ����#���
�� ��& ���
����� � ������� ���� ������������� ���� ������������
�� ��& ��� +��%�� �������� ����&���
R� ��( ��� +��%�� �������� ����(���
C� ���, ��� +��%�� �������� ����,���
( "���#( "���#
4����&�4����&�,�� ��� &,�� ��� &
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
X �� ��� ����-��� .����������� ���������������� ���
Y �� �� ����/��� .����������� ����� ���������� ���
Z 0�� ��� ����1���.����������� ��������������������������.������ ���
[ ��� 2��.����������� ����������� �����������%�� �% ���
��������������� ���� ������������� ���� ������������
�� 3 �������� ��� ����44������������ �.�����������������% ����5������ ��% ���3 ���������!���� ���� �*���
)���������� ��� ����66������������ �.�����������������% ����5����������% ���)�����������7��% ���� �*���
( "���#( "���#
7���� �&��7���� �&��,�� ��� &,�� ��� &
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
�� +��� ��� ��� �)8��������� +���������
��� 9� ����� ��� ��� �)8��������� +������������������� ����
0� ����+��� ���: ��� �)8������������� +���������
� ����+��� ���46��� �)8������������� +���������
0�� �)8������������ +�������������������� � ��
��������������� ���� ������������� ���� ������������
0�� ����9� ����� ���: ����)8������������ +�������������������� � �����
� 3 ������ ���4��� �)8���������� ���������
;� �� ����� ���6��� �)8����������� �� ��������
�� 3����+��� ���4 ��� �)8���������� ��������������� ���� � +���
� ;�����+��� ���6 ��� �)8������������ �� �������������� ���� � +���
( "���#( "���#
9������9������,�� ��� &,�� ��� &
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
;�6 �� �������� �)8�������������������� ��)8
,< �� �������� �)8��� ��� ���������������)8
\,< 0�� ���<���� �)8��� ��� ���������������)8������������
0 ��� :�� �)8��������������)8
XX �� ��������
��������������� ���� ������������� ���� ������������
XX �� �������� �)8�������������������� ��)8
YY �� �������� �)8��� ��� ���������������)8
&� ���&� ���,�� ��� ,�� ���
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
C ����� �� ��� ����,��� ����������� ������ �� ��������� ������
( "���#( "���#
: � �7��� ���,�� ��� : � �7��� ���,�� ���
,�� ��� ,�� ��� :F�����:F����� <�&H��<�&H��
] ��� =��� >?���� ,�<�@AB �����C������� �� ���� ������� ����������������� �?���� ,�<�@
:F��H�����,�� ��� :F��H�����,�� ���
,�� ��� ,�� ��� :F�����:F����� <�&H��<�&H��
^ ��� D��E�D�� ���� ���� < ��� ������� �������������� ��������
��������������� ���� ������������� ���� ������������
^ ��� D��E�D�� ���� ���� < ��� ������� �������������� ��������� ��� �,�+��%�� ������� ��F < �>AB
/�� �����/�� �������6�� �������6�� �����,�� ��� &,�� ��� &
,�� ��� ,�� ��� :F�����:F����� <�&H��<�&H��
OO���� 9�� � ���������� ����) ������� �*���
���� ) ������� �*��� ��������� �9�� � �������
UU���� ! �� � ���������� ����) ������� �*���
���� ) ������� �*��� ��������� �! �� � �������
( "���#( "���#
; �); �),�� ��� &,�� ��� &
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
O 8�� ��� �������� ��5������% ��� ����������������
�� +������ ��� ��� �)8�������������������% ���� �G �&%���
��� 9� ���� ��� ����)8�������������������% ���� �G �&%��� ����� ���� ���� �������� ����
0� 9 +������ ���: ��� �)8�������������+���������
��������������� ���� ������������� ���� ������������
� 9 +������ ���: ��� �)8�������������+���������
0�� ���9� ���� ���: ��� �)8�������������� �����������
�)���)��,�� ��� ,�� ���
,�� ��� ,�� ��� �������� :F�����:F����� <�&H��<�&H��
7��&& ����� ���������HI ��J ��
��������������� ���� ������������� ���� ������������
'������������'������������ �� )*)*
if ($sex==‘M’){echo “Welcome Sir”;}
if ($sex==‘M’){ echo “Welcome Sir”;}else{echo “Welcome Madam”;
��������������� ���� ������������� ���� ������������
echo “Welcome Madam”;}
if ($sex==‘M’){ echo “Welcome Sir”;}elseif ($sex==‘F’){ echo “Welcome Madam”;}else{ echo “Welcome”;}
'������������'������������ �� )*)*
if ($sex==‘M’):echo “Welcome Sir”;endif;
if ($sex==‘M’):echo “Welcome Sir”;else:echo “Welcome Madam”;ednif;
��������������� ���� ������������� ���� ������������
ednif;
if ($sex==‘M’):echo “Welcome Sir”;elseif ($sex==‘F’):echo “Welcome Madam”;else:echo “Welcome”;endif;
'������������'������������ �� + ���+ ���
while ($x>10){echo “The Value of X is <u>$x</u> now <br>”;$x++;}
��������������� ���� ������������� ���� ������������
while ($x>10):echo “The Value of X is <u>$x</u> now <br>”;$x++;endwhile;
'�������������'��������������� ,��- �. ���,��- �. ���
do{echo “The Value of X is <u>$x</u> now <br>”;$x++;} while ($x<=10)
����� � ������� ���� ������������� ���� ������������
'������������'������������ �� *�*�
For($x=1; $x<=10;$x++){echo “The Value of X is <u>$x</u> now <br>”;}
For($x=1; ;$x++)
��������������� ���� ������������� ���� ������������
For($x=1; ;$x++){echo “The Value of X is <u>$x</u> now <br>”;If($x==10)break;}
For(;;){$x++; if($x>10)break;echo “The Value of X is <u>$x</u> now <br>”;}
'������������'������������ �� *�*�
For($x=1; $x<=10;$x++):echo “The Value of X is <u>$x</u> now <br>”;endfor;
For($x=1; ;$x++):
��������������� ���� ������������� ���� ������������
For($x=1; ;$x++):echo “The Value of X is <u>$x</u> now <br>”;If($x==10)break;endfor;
For(;;):$x++; if($x>10)break;echo “The Value of X is <u>$x</u> now <br>”;endfor;
'������������'������������ �� *����*����
$x = array (1,2,3,4,5,6,7,8,9,10);
foreach($x as $v){echo “The Value of X is <u>$v</u> now <br>”;}
��������������� ���� ������������� ���� ������������
$x = array (“one”=>1,”two”=>2,”three”=>3,”four”=>4,”five”=>5,“six”=>6,”seven”=>7,”eight”=>8,”nine”=>9,”ten”=>10);
foreach($x as $p=>$v){echo “The Value of $p is <u>$v</u> now <br>”;}
'������������'������������ �� &�/&�/
while($rows<=8){ // Block 3
for($col=1;$col<=8;$col++){ // Block 2
foreach($x as $v){ // Block 1
if($v==8) break;if($v==0) break 2;
��������������� ���� ������������� ���� ������������
if($v==0) break 2;if($v<0) break 3;echo $v;
}echo “<br>”;
}$rows++;}
'������������'������������ �� ��������������
$i = 0;while ($i++ < 5) {
echo “I am in Outer Zone <br>";while (TRUE) {
echo “Now in Middle Zone <br>";while (TRUE)
��������������� ���� ������������� ���� ������������
while (TRUE) {
echo “Now in Inner Zone <br>";echo “-----------------------------------($i)<br>”;continue 3;
}echo "This never gets output";
}echo "Neither does this";
}
'������������'������������ �� #. ����#. ����
Switch ($x){case 1:echo “Value of X is 1 <br>“;break;case 2:echo “Value of X is 2 <br>“;break;case 3:
��������������� ���� ������������� ���� ������������
case 3:echo “Value of X is 3 <br>“;break;case 4:case 5:echo “Value of X is 4 <br>“;break;default:echo “Value of X is $x <br>”;}
'������������'������������ �� 0��12�3 ������,120��12�3 ������,12
require ‘conf.php’;
require $conffile;
require (“conf,php”);
��������������� ���� ������������� ���� ������������
include ‘conf.php’;
include $conffile;
include (“conf,php”);
'������������'������������ �� 0��4���0��4���12�3 �12�3 ������,4��������,4���1212
require_once(‘conf.php’);
include_once($conffile);
��������������� ���� ������������� ���� ������������
��������������� ���� ������������� ���� ������������
5#�6*��,�7�������#5#�6*��,�7�������#
function hellow($x,$y=“, How are You?”){echo “Hello $x $y <br>”;}
hellow(‘Sir’);hellow(‘Arjun’,’When Did You Come?’);hellow(‘Ram’,’’);
����� � ������� ���� ������������� ���� ������������
hellow(‘Ram’,’’);
Hello Sir, How are You?Hello Arjun When Did You Come?Hello Ram
7����������������%���#7����������������%���#
function power($x,$y){$z=1;for($a=1;$a<=$y;$a++){$z *= $x;}return $z;}
echo “5<sup>2</sup> = “ ,power(5,2), “<br>”;
��������������� ���� ������������� ���� ������������
echo “5<sup>2</sup> = “ ,power(5,2), “<br>”;echo “2<sup>5</sup> = “ ,power(2,5), “<br>”;
52 = 2525 = 32
%���&��7�������#%���&��7�������#
function power($x,$y){$z=1;for($a=1;$a<=$y;$a++){$z *= $x;}return $z;}$pwr = ‘power’;
������ ��������������� ���� ������������� ���� ������
$pwr = ‘power’;
echo “5<sup>2</sup> = “ ,$pwr(5,2), “<br>”;echo “2<sup>5</sup> = “ ,$pwr(2,5), “<br>”;
52 = 2525 = 32
��������������� ���� ������������� ���� ������������
'��##'��##
class LAMP{var $strength=0; var $trainee;function Add_Trainee($name,$designation)
{$this->strength++;$this->trainee[$this->strength]['id']=$this->strength;$this->trainee[$this->strength]['name']=$name;$this->trainee[$this->strength]['designation']=$designation;}
������ ��������������� ���� ������������� ���� ������
}$Session1 = new LAMP;$Session1->Add_Trainee('Loo','SDE');$Session1->Add_Trainee('Goo','JTO');for($n=0; $n<=$Session1->strength; $n++){echo $Session1->trainee[$n]['id'], “...", $Session1->trainee[$n]['name'], "...", $Session1->trainee[$n]['designation'], "<br>";}
1...Loo...SDE2...Goo...JTO
'��##�'��##�88 )�������)�������
class A{function X() {echo "I am From Function X of Class A <br>";}}
class B extends A{function Y() { echo "I am From Function Y of Class B <br>";}}
������ ��������������� ���� ������������� ���� ������
$var = new B;echo $var->X();echo $var->Y();
I am From Function X of Class AI am From Function Y of Class B
��������������� ���� ������������� ���� ������������
9���7�������#9���7�������#
;<<;$*7=�_
� �)�� �)*��H�5"�� �)����H�!����&�̀��-!�M���� �&� ��*5�)&.�'
���������������� ���������������������������������
(���� �)��� �)*��H�5"(���� �)!�N!��<=:'�
;<<;$*_:$*:\/���
M���� �)*5�)*�F�&�&"���F���5�)!�� �)�&�� ���'
���������� ��������������������������������
(����5��� �)*5�)*�F�&�&"#���� !�(&�H����'�
��������������� ���� ������������� ���� ������������
(����5��� �)*5�)*�F�&�&"#���� !�(&�H����'�
;<<;$*�;9_
M���� �)*���5"�� �)�X� �)!�����M��5��H������-!���F���H&� ����.�'
������ ����� �������������������������� ����������� ���������� �����
� �)*���5"(&�H����!�#+ ���S��H�& '�
�,<�
M���&� ��"�� �)�X� �)�-!����&� �*����&.�'
��� ��������� �� ��������������� �� �� ������������ ������� ���� � ����� �� �� ������ ����������� ���� ������
&� �"(&�H����'�
6��6�� ��,� �� ��,� �� 7�������#7�������#
6;�:
&� ���������"�&� ������ ����-!��������&����.�'
��������������� �������� ������ ������������ ����������������������������������������� �����������
� ������������ �������������������
����������"aB�b!�$!��%���a'�
I/7<,�/I:
��F������ �����"�-M������*�&*�����.�'
�������������������������������������� ��� ���
��������������� ���� ������������� ���� ������������
�������������������������������������� ��� ���
(I)��������� �����"�<=:'�
>:�6;�:
� �)��������"�-�������&����.�'
!���� ����� �����"���������������� �������������� ������������� � �� ��
(����)��������"'�
7��#�#��7��#�#�� 7�������#7�������#
7,+$
M������)�"�&� ����&�H ��!�&� ������&�'
� ������ ��� ������������ ����� ������������������� ���������� �� !"�� ���������
(���)"#���C��� ! ���C��� '�
B,+:�
�&�H ��������"�&� ������������!�&� ���������-!�M���H&�*����H��*����-!� �&�H ��������F�..�'
#�������� ��������������
��������������� ���� ������������� ���� ������������
#�������� ��������������
(��������������"a������ �&�H&�����C�F�a!�a a'�
<:;6B/9:
��� �������"�&� �������������-!�M���H&�*����H��*����-!� �&�H ��������F�..�'
������������������������ ����� ������$������
<�������"#�)����C�F� '�
=�9/�_
M���H����5�"�&� �������������-!� �&�H ��������F�.�'
%��������������
=����5"#�)����C�F� '�
: ���� �������7�������#: ���� �������7�������#
�J<�
������&L �"�������� �'
�����������"&���� � ������'���
(�����&L �"(F'�
+,�
�H�M� ���� "��H�M� �M�&�!��H�M� ��F��'
�������$��������� ������ ��� �������
(�����"(F!N'�
����� � ������� ���� ������������� ���� ������������
(�����"(F!N'�
�;�
����������"�������� �'
������ ����������� ������� �����
(��������"NQ'�
<;�6
���� ����"�-�������!�������F.�'
���������� � �������$�������������������������������������������
(����� ���"�!�QQQ'�
: ��; <�7�������#: ��; <�7�������#
I$�J9*7,��:7�
�&�H ����)&L�*�������"�-&� ����&� �� �-!�&� ����H&� �����-!�&� ������&&�� ��-!�M������*���5-!����������*����&.....�'
#����� ��������� ������ ��� ��� �"( !�������
(��F���)&L�*�������"#�������&� ! ��� ! ��A��&Q��c '�
I$�J9*:<<,<
&� �����)&L�*� � "�- �&�H ������5*��������� .�'
������������ ������� ����������� �"( !������� �)� �**�+�����������,����� �� � �������
��������������� ���� ������������� ���� ������������
������������ ������� ����������� �"( !������� �)� �**�+�����������,����� �� � �������
�����)&L�*� � "(��F'�
I$�J9*�:9:7�*64
M����)&L�*&�����*�M"�&� ��������M�&�*����-!� �&�H ������5*��������� .�'
"����������������������$��� ��������������*���� ����������������������������������������
�)&L�*&�����*�M"#��L '�
I$�J9*J=:<$
�&�H ����)&L�*LH� )"�&� ����LH� )�-!� �&�H ������5*��������� .�'
������ ������ �������������������������&������������ �"( !������
( �&����)&L�*LH� )"#&������8�� ���� ������C&�H����& '�
����� �=��������7�������#����� �=��������7�������#
:\:7
&� �����F���"�&� ������������-!�� �)�X�H��H��-!����X ��H �*�� ..�'
�������������������� ������
�F��"#�� '�
+;���<=
�������&&�� H"�&� ������������-!����X ��H �*�� .�'
������������������ ��������������� �����
��&&�� H"?�&V�2'�
��������������� ���� ������������� ���� ������������
��&&�� H"?�&V�2'�
���������� 7�������#7�������#
:7,
����������"�&� ����� ���-!�&� ����CCC.�'
#������� ��� �� ��������
�����?$�H ������&�?�!�(�����
:\+9,6:
� �)��F������"�&� ������������ !�&� ����&� ���-!���������.�'
"���������������� �� ���������������������
(�)� �)���F�����"?!2�!�(9���'�
��������������� ���� ������������� ���� ������������
(�)� �)���F�����"?!2�!�(9���'�
��<9:�
���&� ���"�&� ����&� ���'
������������������ �����������
������&� ���"?&�H��� ���������� �����2'�
�=4��<
&� ����&HM&� "�&� ����&� ���!����&�� ��-!����������.�'
����������� �� �� ������������������$����������������������������
(�� ���&HM&� "?&�H��� ���������� �����2!c!@'�
��������������� ���� ������������� ���� ������������
� ��95 �=> )'9 )( > �+ ) ������ ��95 �=> )'9 )( > �+ ) �����
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm=“Protected"');header('HTTP/1.0 401 Unauthorized');echo ‘You Should Login to View the Content';exit;
������ ��������������� ���� ������������� ���� ������
exit;} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your
password.</p>";}
?>
'( ( ?)=�'( ( ?)=�
<?phpstart_session();Setcookie(‘myuser’,‘trainee1’);Setcookie(‘myuser’,‘trainee1’, time()+3600);
����#����/� #� ��� ���� ��$%� ��� �"�����$%��� ������$%� ��� �����$%� ��� ���� ����
$%����� ������$%�����������&&&&&&�'
������ ��������������� ���� ������������� ���� ������
Setcookie(‘myuser’,‘trainee1’, time()+3600);Setcookie(‘myuser’,‘trainee1’, time()+3600, ‘/olq’);?>
<?phpecho $_COOKIE[‘myuser’];?>
�=��)( >�=��)( >
<?phpstart_session();$_SESSION[‘myuser’] = ‘trainee1’;?>
�� ��(
�� ��)
������ ��������������� ���� ������������� ���� ������
<?phpstart_session();echo $_SESSION[‘myuser’];?>
7�� ����,����7�� ����,����
<html><body><form method=post><p align=center> Enter Your Name     <input type=text name=myname><br><input type=submit name=button value=Process><input type=hidden name=hiddenfield value=100></p><?php$button = $_POST['button'];If($button!='')
������ ��������������� ���� ������������� ���� ������
If($button!=''){$name = $_POST['myname'];$hidden_value = $_POST['hiddenfield'];$shrink = strlen($name);echo "Your name <b>$name</b> is of $shrink Character Length. <br>";echo "Your Hidden Field Value is ", $hidden_value;}?></body></html>
������ ��������������� ���� ������������� ���� ������
������