0% found this document useful (0 votes)
3 views84 pages

Adv PHP Book

The document provides an overview of Object-Oriented Programming (OOP) in PHP, detailing concepts such as encapsulation, classes, and objects. It explains the advantages of OOP, including modularization and reusability, and discusses the use of access modifiers for properties and methods. Additionally, it covers the use of constructors and destructors, as well as introspection for examining classes and objects.

Uploaded by

Sakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views84 pages

Adv PHP Book

The document provides an overview of Object-Oriented Programming (OOP) in PHP, detailing concepts such as encapsulation, classes, and objects. It explains the advantages of OOP, including modularization and reusability, and discusses the use of access modifiers for properties and methods. Additionally, it covers the use of constructors and destructors, as well as introspection for examining classes and objects.

Uploaded by

Sakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 84
To learn the benefits of encapsulating code into functions and classes. To define and use user-defined classes with properties and methods. a a To understand OOP concepts of visibility, inheritance and interface. To study built-in functions for examining classes’ and object's characteristics. a To learn the concept of byte stream representation of an object using serialization ERM nrropuerion 2 9 ee ike C++ and Java, PHP also supports Object Oriented Programming (OOP) concepts. OOP was introduced in PHP3 and improved further. OOP supports cleaner designs, easier maintenance and greater code reuse. It also speeds up the development of large applications. It includes the fundamental connection between data and the code that works on that data. The class and object are the fundamental construct behind object oriented programming. Objects can represent real world entity like student, employee or it can represent conceptual entity link bank account, file. Each object has different values for Properties it possesses. Objects with similar characteristics are grouped together into a single unit called class. The class can contain methods which represents the way in which the object can interact with its data. Ga) Advance PHP(GOA-CA:Sem.tv) __1.2___nroducton to Objet vente Programing a PHP + Advantages of object-oriented Programming: 4. Modularization: The application can be divided into modules, 2. Re-usability: An application can bei {intoa single unit called as class. lass isa programmer de Variables within a lass : ‘fined data type, which includes variables and functions {are called properties which has a name and a value, functions ich represent the actions associated with the class. Methods can accept parameters of any valid data type J Gast isa coltection of objects. an object has properties and behaviour : -nsitive and must conform tothe rules for PHP identifies, by starting with the keyword ‘class’ followed by the name you can define variables and functions as shown below. + We define our own class class name Inside a class, + Syntax; php class class_nane € U Properties 1 Methods 2 /fend oF class [Declaring Properties Toperty ofa class can be defined as private, public or protected, Property declaration is optional. t's a good programming style to declare it. You can add new properties at any time, You can assign default values to Properties, but those default values must be simple public Snanes “Ritika"; public Sage = 18; Using access modifiers, you can change the visibility of properties. ° Properties that are accessible outside the class using object should be declared as Public; properties on an instance that can only be accessed by methods within the same class should be declared private. Finally, properties declared as protected can only be accessed by the ‘object’s class methods and the class methods of the classes. inheriting from the class. snap (@0h-Ch:Sen.N)__12.__ HOSEN Oy it ae the wsiyof das properties is tonal fa ahi eg iby default “ (ork cese iy class Deno. ‘Hos oe sestgnata ‘ y private Snane = "Athory"5 fonction protected $age = 20; S osane public eines = “SFM: wer y echo “testa es + Here Snane is acessible inside class methods only, Sag Is acai ng, methods and class methods of lasses inheriting from class Demo. sclatsinat cutside the cass using an object ofthe classtype ER) declaring Methods + Amethod i function define inside a ass. PAP, most methods ace, ‘of class in wich the metho resides. Nesp ce, enp_ne + Yin mete te ssi vate conainsareeence wan cee ia, WEY static Prope She method Using Sens, vars of an ject ean be ares ine ang + PAP ls Yous function ofa dass + Riso to access me + Using access modifiers, you can change the visibility of methods. Methods ig, * MON asSHs me accessible outside the class using object should be declared as public methoisegy functions ates instance ht can ony be called by methods within the same dasssholedeg, rma Private, Final, methods dered as protected can only be cael from wing, seas object's class methods and the class methods of classes inheriting fromthedas, + S¥mWW self: fining the visibility of dass methods is optional: if a visibility isnot sped Program 1: Wi you can ste, the method is publi mato, + For Example: PHP script to define a dass Employee, With methods toscating OPP display employee details, oe enp_cestgnationasa;, ? c , : . Sopopetisofthecamen on PEE static Property and static m “ ope, which are variables of das an accessed by referencing the property with the class les of dass and canbe + moore mats in ans ot teeter a sn tes, we caper funens re asocated the dss anda ian eek a permitted to access only static met a Meetat They are TOPE sing the self eyo Syne se :staie van nave eee an Concept of state propeny and wat eto’ Es expe static iethod ‘+ PAP allows you to define static name, “Any method declared as st vii ‘and static variables, + Insidea class, you cen refer to the static Program 1.1: Write a PHP script to illustrate th atic “php static $count; [static property public static function updatecount() £ (/statie method return self: counter; ) 4 } cvanple static: :Scount = 1; for$i.= 05 $i. <5; 1451) ( \ 1 82 TRE value Is: "example static: upatecount() “aR PHP IOBA-Ch:sea.t) 15 __Inuodyton oes rere Programing output: The value ist 2 The value is: 2 The value te: 3 he data srr defined by cls called as Oe. You Gein cats one and then declare eject of hat das BEng an OME iN lass snow as asantatonlstantaing an object rege enor acto noe athe et © Reeivinewtpapiennetest teppei «ho eet ha ts em India en. Tach ee eo manipulate edt, * Objet ofiterent clasts can interact with each other without knowing a other's data or code, itis sufficient to know the type of message accepted and typ response returned by the object ! Declaring an Object: + Todeclarean cbjectofa given class, the new keywordisused: + Syntax: ; Sovject = new Class; + Bample: ‘erp = new Employees ‘Accessing Properties and Methods: a * Class methods and properties can be directly accessed through the object instance ‘using the object access operator {-») notation, + Syntax: Sobject-property_nane Af visibility of property is public oY Sobject->nethod_nane(Larg, + Example: ‘Semp-raccept(a,"atharv’, "Manager"); Senp->display(); * Note: Classes are manipulated at design time when you make changes to the methods oF properties and objects are manipulated at runtime when values are assigned ‘their properties and their methods are invoked. ‘Aavance PHP (BBA~CA: Sem. 1) dass which is 4, Usually it Initializing an object using Constructor: + To initialize the object, Constructor is special type of function of sally executed as any object of that class is created or insta starts with two underscore characters. + syntax: Function _construct(args..) € WaeFinivion 2 + You may provide a list of arguments following the class name when object. These arguments are passed to a constructor, that initializes the propert the class, Destroying an object using Destructor: ‘+ When an object is destroyed, such as when the requested page has completed runnin, when the variable falls out of scope, when itis explicitly set to null or the end of the scriptis reached, its destructor is called. Destructor does not take any parameters + Syntax: function __destruct() £ HeeFinition ? This helps to perform any last minute clean up, such as closing file handle or database connections that might have been opened using class. ‘rogram 12: Write a PHP script to define a class Employee with enp_code, enp_nane and s°0_designation as data members, Define constructor and destructor for the cass. Also define display0 function to display employee details. php class Employee € private Senp_code; private Senp_nane; private Senp_designation; function __construct($e, $n, $4) t $this-renp_codes$c; tantiating an ies of /eonstructor definition $this-denp_name=$n; gesignation=s45 Ny J pnction display {ono “cervenp code: sthis-renp_codes 1 on _aestrvce() //destructor definétfon ot ‘ ‘echo sebroopject 45 destroyed”; fed automatically when object 1s created seormanoger"5 Jrconstructor call Senpnnew Empnoyee(Ser5%5 $enp-2display( output: Object iscreated ‘Emp Designation: Manager Object is destroyed Tn above PHP script, the statement $emp-new Enployee( me constructor function automatically when object is created and atthe end ters destructor iscalled automatically, Program 1.3: Write a PHP script to define a class Rectangle with length a data members. Define constructor and destructor for the class. Also defir perineter() functions to display area and perimeter of a rectangle. Length = sthis-o1, y function area() ‘ Breadth= $this ses, *$this-9b; echo “cbroarea of rectangle =gar y function perineter() t $-2*(Sthis->14$this-»b); echo “cbroPerineter of rect ectangle asp"; ; $0"; function _destruct() //destructon detintt ‘ inition echo “area() Sr->perimeter(); Length=3.2, Breadth =5.4 Area of rectangle = 17.28 Perimeter of rectangle = 17.2 the statement $renew Rectar Me ng2e($1, $6) invokes the constructor wutomatically. Advance SHP(BGA:Ck:Sem.M)__19_inrodoono Obes rened Programming PHP jSPECTION. SS Cas Ttis the ability ofa program to examine an object's characteristics, such as its mame, parent elas (ifany), properties and methods. . ‘With introspection, you can write code that operates on any class or object. You don't need to know which methods or properties are defined when you write your code: Instead, you can discover that information at runtime. Examining Classes: | mine whether a class exists, use the ¢lass_exists() function, which takes in and returns a Boolean value Syes_no = ciass_exists(classnane); Alternately, you can use the get_declared_classes() function, which retums an array of defined classes and you can verify the classname in the returned array: Syntax; classes = get_declared_classes(); + You can get the methods and properties that exist in a class (including those that are inherited from super classes) using the get class nethods() and get_class_vars() functions. These functions take a class name and returns an array. Syntax; Saethods = get_class_nethods(classnane); Soroperties = get_elass_vars(classnane); + Note: get_class_vars() returns only properties that have default values; there's no vay to discover uninitialized properties. Use get_garent class() to find a class's parent cass name, Syntax:Ssuperclass = get_parent_class(classnane); Examining an Object: class to which an object belongs, first check 4s object() function, then get the class with the get cla Syntax syes_no = is object (var); — $classnane « get_class(object); + Before calling a method on an object, you can check that it exists using the sethod_exists() function: Syfitax $yes_no = method _exists(object, method); Calling an undefined metnod triggers a runtime exception, get_object_vars() returns an array of properties that are set in an objec. Synatx Sarray = get_object_vars (object); s an object using the Program 1.4: Write a PHP script to illustrate the use of functions to examine characteristics of classes and objects, <2php class to. private $310, #y5 function A($3) Advance PHP (BEA-Ck:Sem.N)___130___tnteduetlon to Object Oriented Programming In PHP. £ Sehis-oy-5a; ‘echo "<5R> Constructor A is called”; ) Function aizplayac) € echo “cBR> xoSthis-ox yaSthis-oy"s 2 d class 8 extends A t private $p,5ay Function 8($1, $9,$n) 2 function displaya() f echo “
peSthis-»p geSthis-r4"; } 2 $0by = new B(20,30,40); $obj-rdisplaya(); $0bj->displays(); echo “cBR>Functions examining classescBR>"; echo "
Class A exists or not: *; echo class_exists(‘A"); echo “cBR> Class C exists or not: “; echo class_exists("C'); echo "cBR> Get existing all classes:
"; $allclasses= get_declared_classes(); echo."
Get methods of class A:
"; print_r(get_class_methods(‘A')); echo "
Get methods of class 8:
"; print_r(get_class_methods('8")); advance PH (GEA-CksSem.N) Ut Seen Tt % echo “
Get variables of class AcBR>"; var_dunp(get_class_vars('8"))5 echo " Get variables of Class B(no property with default ve print_r(get_class_va' ‘echo "
Parent of cla! obj); //from object of class 8 U/ fron class nane //n0 parent so no output echo get_parent_class(‘A"): ‘{/Functions examining objects ‘echo ~obj1 is obejet or not: echo is_object($0bs1); ‘echo "rethod displayA() exists or not: echo method exists(SobJ, ‘displayA); echo “<éRoMethod displayC() exists or not: °; ‘echo method_exists($obj, ‘displayc’); variables of class 8 using object(no property with default print_e(get_object_vars($0b3)); output: Constructor Ais called Constructor Bis called x=10y=20 P=30 4240 Functions examining classes Class Aexists ornot:1 //Class Aexists Class Cexists ornot: // Class C does not exists, Get existing all classes: Get methods of class A: Asonse Dib (REA-CA.Sem.N)_L12__nvodton Oe rd Pegi noe ARPA) // Methods ofa cass A are returned as array > A Array elements Get methods of class B array ({0]=> 8 [1] => displayD (2) => A [3] => display Methods ofa class Bare its own methods along with method of base cas — returned as array elements Getvariables of class A arry(0){)_//plz check it should output arra Get variables of class B(no property with defa array() _ //plz check t should output array( Parent of class B A //from object of class B A //fromlass name B Parent of class A: (as case & doesn't have base class, nooutput is displayed obejctornot:1 //objis declared so output is 1 aobjtisobejetor not: //ebjt isnot declared so error is dsplayed i] =>20) ie) => 10) Get obj class name: B ‘Method displayA() exists or not: 1 Method displayC() exists or not: // //displayA) method exists so output is 1 ‘/AisplayC) method doesn’t exists so no output Get variables of class B using object(no property with default value) Array 0) //plz check it should output arra The conversion of any PHP value to a byte stream representation is called as Serialization. This byte stream can be stored ina file. Syntax: string serialize(value); When an object is serialized, name of the class. The methods in an object will not be saved. To convert a byte stream representation back to a PHP value, use unserialize() will save all variables in an object. Also, it stores the function. When you unserialize an object, its class must be defined before unserialization occurs. Unserializing an object whose class is not yet defined puts the object into stdClass, which is useless. Syntax: value unserialize(string); wale unserfalize(string)§ niroeucton we Obfct Oriented Programming In PHP Advance PHP (B6A CA: Sam. V) Program 1.5; Write PHP script to illustrate the use of serialize) and unserialize functions, ‘ Object 1s Inittalized™; ? Function displayA() echo “
xeBthis->x yaSthis->y"; £ //$0b3 converted to a bytestrean s2e($0b9); ytestrean representation: Sbytestrean” 5 a [/bytestrean is written to a file $p=Fope furite( sfp, Soytestreas) Fedose($fp); $Fp=Fopen( “test txt”, aa Sbytestreantafread( Sfp, filesize("test.txt")); //read bytestrean from 2 file Felose($fp); echo "
"; Sobji-unsersalize(sbytestreaml); echo "
Object after reading from a file"; I/converts bytestrean back to an object Sobj2->displaya(); echo "
"; / displays details of Sobji var_dunp($obj2) ; Object before writing toa fue xel€ y=22 Bytestream representation: 0: Object after reading from a Al xele y=20 ‘using var_dun object(aye2 (2 ":privatel=> int/20) > ‘riented Programming rr uthods fom another cass called lity ofa elas to derive prope Inheritance. pron + The class wows properties and method are inherited into a ne cas (isan theca which ier ocalledaedervadclams ‘non + The derined clas do not have to define all the properties and functions again again. as these ae inherited from base cass that possesses it, This allows re wsa0I57 of the cde and specs up the overall development proces: + Tp inherit the properties and methods from one class into another class wee‘ fertends keyword in te lass definition, followed by the nameof the base class. * The public property or method of base class will be public in the dervea sts The protected members wll remain protected after inheritance. The private Proper Rot be inherited, but i can be manipulated through public inherited methods of PASE ass. The private methods of baze class canbe invoked by methods of derived Gass is caled a3 base + Syntax: 1255 derived_classnane extends base_classnane ; 7 Uoroperties Methods 2 + Brample: class Employee t PME Sepcode, Semp_nane, Sen designation; {2555 empvessalary extends ployee 4p ivate Sbassc pay, Searning, Sdeduction; * The classEepoyeesslary contains the Svasic_pay, earning and Sdeduction, as well as the Semp_code, Senp_nane and Senp_designation properti ited from the »_code, 4 it ; p_des: ‘Properties inher + Ifa derived class has a class, the property or m the property or metho value of the property o the child. Property or method with the same name as one in its parent lethod in the derived class takes precedence over, or overrides, d in the parent class. Referencing the property returns the n the child, while referencing the method calls the method on pen A 2p ania when Be oe : rom Sace,use the parentsmethodd Rotation, oN % en: 389803 inthe derived + sim struct ea, parent: €or define a class Em ine a PAP script €0 whee wi Fraga Ue Wee 2 er Die constr SaaS and emp. ses1g0 205) rive a cass EmployeeSalary from Employ \ Sherbet fan pensar eee ena ee rem member func eo “eh? Stass enployee ‘ jonp_code, Semp_nane, $87 C2s4anation, privase SempTeeruct($ey$084) (Constructor Prenton construct (SE, etsy ‘ ‘gthis->emp_coder$es $this->enp_name=$nj , ‘sthis-renp_designation=$45 ‘echo “
object is created”; ) function display) { ‘echo “enp_nane; echo “
ap Designation: *-Sthis->enp_designation, } function __destruct() t [[destructor definition echo “cbro0bject is destroyed"; , y class Employeesalary extends Employee ¢ private Sbasic_pay, $earnings, $deduction; function Enployeesalary($c,$n,$d,$b,$e,$dd) « °C savance PHP (@8A- C4 am) ‘sents ouasic.p semis dean ‘sents-ceauet y function Cateut « echo “cbr ‘sents saeduct y y seus sn 0 ‘so-100005, Sen500; 007505, Senpenew Enp ‘Semp->4ispl Senp->Caleu » output: Objects Emp Code Emp Nan Emp De Net Sal Advance PHP(DOA-CA:Sem.1Y) 136 _tnzagucton object lente Programming In PHP { parent::_construct($e, 0,4); Sthis-rbasie_payssb; Sthis-rearningsese; Sthis-rdecuction=sad; + Function Caleulatesatary(y ‘ echo! "sbr> Net Salary(Rs.) :°.(Sthis-sbastc sete (Stmis-obasic pays senis-rearnings- } > Sco; Snevathary * $0="Manage 0=10000; $0500 $4750; Senpenew Enployeesalary/$e, $n, $4, $b, $0, Sad); Senp-rdisplay(); Senp->Calculatesatary(); output: Objects éreated Emp Code: EmpName: Athary Emp Design NetSalary(s) object is destroyed FER Final Methoa * Hf you declare the method using final Keyword in superclass/parent class, then ‘ubelass/child class can’t override that method. Method should not be overridden de tosecurity reason, ters and constants cannot be declared final, only classes and methods may be Seen ee eeeeE Eee EES, rogramming in PHP, Advance PHP (BBA-CA:Sem.M)__1.17__litroduction to tj Oriented Programing method. Program 1.7: Write a PHP script to illustrate the concept of final meth phe class A ‘ private Snessage= "Hi; final function display( € echo $this->message; y + class B extends A € function display() « ‘echo "Hello"; y ? output: Fatal error: Cannot override final method A: :4isplay() £0: \xanpp \htdocs\00P\Finalmethod. php on line 12 In the derived class 8, display( function can't be redefined as itis declared as final in base class A, s0 you will get error message. Program 1.8; Write a PHP script to illustrate the concept of final method. "; final function display() ‘ echo $this-smessage; » } class B extends & 118__lntodtlon tobe orenag : Som.tV) . ance PHP (BBA-CA: Sem. Object Orlnted Programming a PHP, ass : Advance PHP(BBA=CA:Sem.1Y) 4.18 __ntreduetion to Object “ pact method" om ‘ echo "Non-abstr function éisplays() “ echo "Hello"; ; : class 8 extends & > S0b5enew : . public function one() + Here $0bj, cisplay) function of Ws Base dass A without overriding. member function display9, Abstract Class and Abstract Method ‘Abstraction isa way of hiding information. in. abstraction, there should be at least one tust Be declared but not defined. © eaesg’? OME contains at least one abstract method must also be declared as Qbiect of dass B can invoke display) fun it Also $obj invokes its own abstract class classname ( Mabstract method declaration 1 von-sbstract method definition d Characteristics of abstract class: 7 TA SESRRUSTEE am abstract Keyword that must be written before thie class for it tobe an abstract class, * FAS class cannot be instantiated. Only the class that RATE class can be instantiated. There can be meat left undefined iplements all methods of an wn one methods that can be abstract class doesn’t define all abstract tantiated, fe the concept of abstract class and abstract php abstract class 4 £ abstract function one(); Public function twa() 2 ed by subelassebr/>"; echo “Abstract Function one defi ) > Sobj = new 8005 output: contains no data variables, “ses ot tal how these sseiods seul te implemented. The na {implementation depends upon the class which implements them. Characteristics of an tnt incode. Interface is similar toa class except that it cannot contall * An interface can define method names and arguments, but not the contents of th methods. i { Allimethods declared in an interface must be public. : * fay classes implementing an interface must implement all methods defined by th interface. + Aclass can implement multiple interfaces. interface is declared using the “interface” keyword. . ces can't maintain Non-abstract methods. of an Interface: + Itseparates the implementation and defines the structure, S + _Itis used to definea generic template. <_Hisusedtodefineagenerictemplate. smplenents mytntertace Hethod on0 11 implemented; Public function metnad toot) ‘ echo “WARY nethod to 44 tnplewentes; ) output: captule. which contains properties ise properties This is called as Encapaua palates re hidgen from any other class and can be accessed ion of that class. The data in class is hidden from internal implementation without affecting overall alty, The details of implementaticn of class methods are hidden from the the object. Agree Pt (PEA Cb bam 4) se Any access needed 1 public method. The ectared as public as well eee Sc recoae details at any time without affecting code that uses saity property values of an cbject built from your cass without 1 enectty property wal aanittremintge eres To understand server information. To study about processing forms. To lear how to use sticky forms. Sisresenre serpin Ase INTRODUCTION Say = * Form processing is essential component in almost ev forms as interface user communicates with Server. * In PHP program, form is used to display the form, Which in text boxes, checkbox, radio buttons, buttons etc. After creating a f; data inte it and that information is sent to the server, which wi database and it Sets stored into it, another Way is to pull the data and display on to form, to retain information on to the form sticky forms. * Along with forms we use GET, POST variables to send the data to u S_SERVER[] global array is also used for serv: Tesponse headers of page. = ery volves Huy Razr er informati it is | ee Il addition to PHP_SELF and REQu! ‘ST_METHOO number of useful elem, request auto global amy == ‘ents that provide information on tot =- * SLSERVER array Contains useful information from the web server. Blobal variable it contains information about headers. path. hos _ With these global indices, the S_SERVER array contains values for tt Usted with the specification of cot (Common Gateway Interface). | Returns the port being used on the user's vmsente with the web machine to comm {executing seript = 2. [sewer onteu_ owe) | Rewme ee —————_| server. Rew rsion of the Common TT retamns the absotute pathname of the "way Interface (CGI the serveris using 16. | §_senven{ ‘scnzPT_FILEWHE") an 3. | § SeAVERE SERVER abOR'] Returns the IP address of the hi “| ~ currently executing srint addres of the host server me he 4. | SERVER “SERVER NanE™] Retums th ame Retums the value ei = the name ofthe host server ch we. | ssenvent Seaver fom) ee waar 38 www nirali. com), SERVER_ADMIN direeti 3 | sSenvenl Semen Sortuane’y pt runs ona configuration file (if your crn Returns the server Henan ye defined for etver identification string virtual host, it will be the valu {such as Apache/2.2.24) Retums the na 6. | $_SERVER[ “SERVER_PROTOCOL” that virtual host) (Such as me and revision of the soneone@u3schools cos). {information protocol (such as HTTP/11), | ‘on the server machine 7. | s_SeAVERE REQUEST_METHOD] Returns the request method used to access 20. | $_SERVER{“SERVER_PORT'] eae cerca ‘the page (such as POST). | being used by 5 8, | $_senvent‘ReQuest_tine'] Returns the timestamp of the stant of the] | communication Sucha5 50) ae reque San of the jon and virtual host quest (such as 1377687496). 21. | s_senven( sever_stonarune'] | Returns the server vers -generated | 9. | S_SERVER( “QUERY_STRING ] Returns the query string if the page is 7 name which are added to server-g accessed via a query string. ages. 40. | $_SeAvERt “wTTP_accePT"] Returns the Accept header from the : system based path to the ‘cumentroquese | 2 Vater om) th 22. | $ seaven{'pat_transLaTeD"] | Returns the file system | current script. 1, | $ seAVERL 'HTTP_accePT_cHanseT’] Returns the accept charset header from ‘current script. the current request (such as utf-8, Is0- 23. | $_senven{scerpT_naNe*) pmatiimns the path Of05 current page. 8859-2) 24, | s_SeRveRt “scarp URI") Returns the URI of th ha 1 |S SERVER HTTP_ROST Retums the Host header from the current Tequest. + The Apache server also creates entiies in the $_SERVER airay for each HTTP hea 1B. | S_SERVER[ HITP_REFERER'] Returns the complete URL of the current ‘he reuest For each ay, the header name converted touppercare hyphens (ae Pegs {ck reliable because not all user- turned into underscores (_), and the string “KTTP_* is prepended. For example, Agents support i) : re try forthe User. lerhas the key "HTTP_USER_AGENT. 7a, |S SeRVERT WTTPS] Isthe script queried throughasecarea>| | entry forthe User-Agent head: “y protocol? + The twomost common and useful headers are: 15, | SERVER’ ReNOTE_ADOR") Returns the IP address from where the user ‘ (eg. “Mozila/s.0 1. WTTP_USER_AGENT: The string the browser used to identify itself (¢8., "Mo: (Windows 2000;U) Opera 6.0 (en]"). ia it et to the current page 2, HTTP REFFERER: The page the browser said it came from to get to th pag (c.g. "netp://wm.exanple .con/last_page.htsl’) is viewing the current page. Returns the Host name from where the User is viewing the current page. 416, | $_SERVER[ 'REMOTE_HOST")

You might also like