PHP Notes 3mks PDF
PHP Notes 3mks PDF
PHP Notes 3mks PDF
1 checkdnsrr
It checks the DNS record of corresponding the host or ip address.
2 closelog
It closing the connection of system logger
3 define_syslog_variables
Initializes the syslog variable
4 fsockopen
It is used to open internet or Unix domain socket connections
5 gethostbyaddr
It returns the error code from the last connection
6 gethostbyname
It is used to get the internet host name which has given by IP
Address.
7 gethostbynamel
It is used to get a list of the IPV4 addresses which has given by Host
name
8 gethostname
It is used to get the host name
9 getmxrr
It is used to get the MX records to Host
10 getprotobyname
It is used to get Protocal number which has associated with protocal
name
11 getprotobynumber
It is used to fetchs all result rows and returns the result set as an
associative array
12 getservbyname
It is used to get Protocal name which has associated with protocal
number
13 getservbyport
It is used to get internet services which has corresponding to port
number.
14 header_register_callback
It will register the function that will be called when PHP start sending
output.
15 header_remove
It is used to remove previously set headers
16 header
It is used to send the row of HTTP Headers.
17 headers_list
It is used to returns a list of repose headers sent
18 headers_sent
It will check whether header have been sent or not.
19 http_response_code.
It used to get or set the HTTP Response.
20 inet_ntop
It used to convert internet package to human readable formate.
21 inet_pton
It used to convert human readable Ip address to in_addr format.
22 ip2long
It used to convert ipv4 address to long integer.
23 long2ip
It used to convert long integer value to Ipv4 address.
24 openlog
It used to open connection to system logger.
25 pfsockopen
It used to open internet or unix domain socket.
26 setcookie
It used to set the cookies.
27 setrawcookie
It used to set the cookies.
28 socket_set_blocking
It is an alias of stream_set_blocking(), It has block or unblock options
for stram mode.
Ans.:- The default error handling in PHP is very simple. An error message with filename,
line number and a message describing the error is sent to the browser.
PHP Error Handling:-
When creating scripts and web applications, error handling is an important part. If
your code lacks error checking code, your program may look very unprofessional
and you may be open to security risks.
This tutorial contains some of the most common error checking methods in PHP.
We will show different error handling methods:
Simple "die()" statements
Custom errors and error triggers
Error reporting
Basic Error Handling: Using the die() function
The first example shows a simple script that opens a text file:
<?php
$file=fopen("welcome.txt","r");
?>
To prevent the user from getting an error message like the one above, we test
whether the file exist before we try to access it:
<?php
if(!file_exists("welcome.txt"))
{
die("File not found");
}
Else
{
$file=fopen("welcome.txt","r");
}
?>
Creating a Custom Error Handler
Creating a custom error handler is quite simple. We simply create a special
function that can be called when an error occurs in PHP.
This function must be able to handle a minimum of two parameters (error level
and error message) but can accept up to five parameters (optionally: file, line-
number, and the error context):
Syntax:-
error_function(error_level,error_message,
error_file,error_line,error_context)
1 to
Required. Specifies the receiver / receivers of the email
2 subject
Required. Specifies the subject of the email. This parameter
cannot contain any newline characters
3 message
Required. Defines the message to be sent. Each line should
be separated with a LF (\n). Lines should not exceed 70
characters
4 headers
Optional. Specifies additional headers, like From, Cc, and
Bcc. The additional headers should be separated with a
CRLF (\r\n)
5 parameters
Optional. Specifies an additional parameter to the send mail
program
As soon as the mail function is called PHP will attempt to send the email then it
will return true if successful or false if it is failed.
Multiple recipients can be specified as the first argument to the mail() function in
a comma separated list.
if(!empty($name)){
if($name =='COURSE'){
// creating an array to store information
$tutors []= array();
}
$elements = $name;
}
}
// Called to this function when tags are closed
function endElements($parser, $name){
global $elements;
if(!empty($name)){
$elements =null;
}
}
// Called on the text between the start and end of the tags
Case sensitivity : Variable names, properties and methods are all case sensitive.
Mismatching quotes, parenthesis or curly braces will throw an error.
Conditional Statements : 3 common gotchas.
Line breaks: Always end statements in semi-colons to avoid common line
break issues.
Punctuation:Trailing commas in object declarations will trip you up.
HTML id conflicts.
Variable Scope: global versus local scope.
string replace function isn’t global.
parseInt should include two arguments.
‘this’ and binding issues.
Function overloading: Overwriting functions, as overloading doesn’t exist.
Setting default values for parameters in case you omit them.
For each loops are for objects, not arrays.
switch statements are a little tricky.
Always check for Undefined before checking for null.
Function location may matter.