This PPT for PHP covers:
Working with Data
Form and input elements validating the user input, passing variables
between pages, through GET, through POST, through REQUEST and
RESPOND, string functions - chr, ord, strtolower, strtoupper, strlen, ltrim,
rtrim, substr, strcmp, math functions - abs, ceil, floor, round, fmod, min,
max, pow, sqrt, rand, array functions - count, list, in_array, current, next,
previous, end, each, sort, rsort, Rest API.
The document discusses various aspects of working with PHP forms and form data, including:
1) HTML forms use tags like <form> and <input> to collect user data in fields like text boxes and radio buttons. Forms can use GET or POST methods to transmit the data.
2) PHP provides superglobal variables ($_GET, $_POST, $_REQUEST) to access transmitted form data in the backend.
3) It's important to validate form data for security, like checking for required fields and proper email/URL formats. Functions like filter_var() and regular expressions can help validate different field types.
This document discusses PHP forms and form validation. It explains that forms allow users to enter and submit data via HTML forms. The form data is sent to a PHP file for processing via the POST or GET HTTP methods. It provides examples of basic PHP forms using POST and GET, and how to display submitted form data. The document also discusses the differences between GET and POST, and emphasizes the importance of validating form data on the server-side to protect against hackers and spam. It provides examples of validating URLs, emails, names, and other common form fields.
The document discusses PHP form handling and validation. It covers using the GET and POST methods to submit form data, and the PHP superglobals like $_GET and $_POST that contain this submitted data. It then discusses validating form fields, including checking for required fields, validating names, emails, and URLs. It provides code examples for validating field values and displaying error messages. It also covers basics of SQL like using CREATE TABLE, INSERT, SELECT, WHERE clauses, and JOINs.
The document discusses form processing in PHP. It describes how PHP processes incoming HTTP requests and places data into global variables like $_GET and $_POST. It covers creating basic forms in HTML and how form data is submitted via GET or POST. It also discusses validating form data on the server side to ensure security and integrity. The document provides examples of using different form field types like text, radio buttons, checkboxes, selects and textareas. It introduces patterns for handling form submissions, like model-view-controller (MVC).
Introduce the Java Enterprise (J2EE) model
Present the Hypertext Markup Language (HTML) tags
Present the Hypertext Transmission Protocol (HTTP)
Define an HTTP client request, server response, and HTTP request methods
The document provides an overview of the Web Client Model and HTTP requests and responses. It discusses:
1) The J2EE model and how servlets and JSPs are used.
2) HTML tags like forms, inputs, and selects that are used to collect data from users.
3) How HTTP is used to transfer data, including the different request methods like GET, POST, PUT, and how requests and responses are structured with a start line, headers, and body.
GET and POST Methods - The client browser uses two methods to send information from the client to the webserver,These methods are GET Method and POST Method
Project link : https://phpgurukul.com/get-and-post-methods/
The document discusses PHP forms and form handling. It explains that the $_GET and $_POST superglobals are used to collect form data submitted via GET or POST methods. It provides an example HTML form that submits to a PHP file and displays the submitted data. The differences between GET and POST are outlined, including when each method should be used. Validation of required fields is demonstrated with PHP code. Other PHP topics like dates, times, and including files are briefly covered.
The document discusses various aspects of working with PHP forms and form data, including:
1) HTML forms use tags like <form> and <input> to collect user data in fields like text boxes and radio buttons. Forms can use GET or POST methods to transmit the data.
2) PHP provides superglobal variables ($_GET, $_POST, $_REQUEST) to access transmitted form data in the backend.
3) It's important to validate form data for security, like checking for required fields and proper email/URL formats. Functions like filter_var() and regular expressions can help validate different field types.
This document discusses PHP forms and form validation. It explains that forms allow users to enter and submit data via HTML forms. The form data is sent to a PHP file for processing via the POST or GET HTTP methods. It provides examples of basic PHP forms using POST and GET, and how to display submitted form data. The document also discusses the differences between GET and POST, and emphasizes the importance of validating form data on the server-side to protect against hackers and spam. It provides examples of validating URLs, emails, names, and other common form fields.
The document discusses PHP form handling and validation. It covers using the GET and POST methods to submit form data, and the PHP superglobals like $_GET and $_POST that contain this submitted data. It then discusses validating form fields, including checking for required fields, validating names, emails, and URLs. It provides code examples for validating field values and displaying error messages. It also covers basics of SQL like using CREATE TABLE, INSERT, SELECT, WHERE clauses, and JOINs.
The document discusses form processing in PHP. It describes how PHP processes incoming HTTP requests and places data into global variables like $_GET and $_POST. It covers creating basic forms in HTML and how form data is submitted via GET or POST. It also discusses validating form data on the server side to ensure security and integrity. The document provides examples of using different form field types like text, radio buttons, checkboxes, selects and textareas. It introduces patterns for handling form submissions, like model-view-controller (MVC).
Introduce the Java Enterprise (J2EE) model
Present the Hypertext Markup Language (HTML) tags
Present the Hypertext Transmission Protocol (HTTP)
Define an HTTP client request, server response, and HTTP request methods
The document provides an overview of the Web Client Model and HTTP requests and responses. It discusses:
1) The J2EE model and how servlets and JSPs are used.
2) HTML tags like forms, inputs, and selects that are used to collect data from users.
3) How HTTP is used to transfer data, including the different request methods like GET, POST, PUT, and how requests and responses are structured with a start line, headers, and body.
GET and POST Methods - The client browser uses two methods to send information from the client to the webserver,These methods are GET Method and POST Method
Project link : https://phpgurukul.com/get-and-post-methods/
The document discusses PHP forms and form handling. It explains that the $_GET and $_POST superglobals are used to collect form data submitted via GET or POST methods. It provides an example HTML form that submits to a PHP file and displays the submitted data. The differences between GET and POST are outlined, including when each method should be used. Validation of required fields is demonstrated with PHP code. Other PHP topics like dates, times, and including files are briefly covered.
This document provides information on handling PHP forms. It discusses how the $_GET and $_POST superglobals are used to collect form data via the GET and POST methods. It provides an example of a simple HTML form and how to display submitted data using $_GET and $_POST. It discusses when to use GET vs POST and how to validate form data with PHP to protect against malicious code. It also covers required fields, validating email addresses and URLs, and keeping form values populated after submission. The document is intended to guide readers through processing PHP forms securely and with validation.
The document discusses the servlet model and how servlets handle HTTP requests and responses. Some key points:
- Servlets use doXXX methods like doGet, doPost to handle different HTTP request methods. These methods receive a request and response object to access data and send a response.
- The request object provides access to parameters, headers, and attributes while the response object sets headers and content type for the response.
- Sessions allow servlets to access user data across multiple requests using attributes. Cookies can also be used to manage sessions between the client and server.
JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. It is used primarily to transmit data between a server and web application. JSON is language independent, lightweight and easy to read/write. It is used to transmit structured data over network connections, by web services and APIs to provide public data.
07 application security fundamentals - part 2 - security mechanisms - data ...appsec
This document discusses data validation concepts and best practices. It covers four core concepts: 1) whitelisting and blacklisting known good/bad values, 2) validating data length and format, 3) validating data before use in SQL, eval functions, or writing to buffers, and 4) encoding output to prevent XSS. Real world examples demonstrate how failing to validate data can enable SQL injection, XSS attacks, buffer overflows, and more. The document advocates restricting input length, whitelisting valid characters, encoding output, and using safe functions like strncpy() to avoid security issues.
This document discusses PHP arrays and superglobal variables. It explains that arrays allow the collection of related elements in a single variable and allow access, iteration, addition and removal of elements. Array keys can be integers or strings and do not need to be sequential. Multidimensional arrays are also covered. The document then discusses PHP superglobal variables like $_GET, $_POST and $_SERVER that provide access to form data and server information. It provides examples of accessing submitted form data and server variables. Object-oriented programming in PHP including classes, objects, inheritance and interfaces is also summarized.
1.1 For each of the HTTP methods,GET,POST, andPUT, identifythe corresponding method in the HttpServletclass.
1.3 For each of the following operations, identify the interfaceand method name that should be used:
Retrieve HTML form parameters from the request
Retrieve a servlet initialization parameter
Retrieve HTTP request header information
Set an HTTP response header
set the content type of the response
Acquire a text stream for the response
Acquire a binary stream for the response
Redirect an HTTP request to another URL
1.4 Identify the interface and method to access values and resources and to set object attributes within the following three web scopes:
Request
Session
Context
1.5 Given a life-cycle method: init,service , or destroy, identify correct statements bout its purpose or about how and when it is invoked.
1.6 Use a RequestDispatcher to include or forward to a web resource.
The document discusses various aspects of building a web application using Java including HTML forms, handling form data with servlets and requests/responses, connecting to a database using MySQL and its Java connector library, using the MVC pattern to manage database requests, and implementing user authentication with a login servlet that verifies credentials against a users table.
5.1 Identify the interface and methods for each of the following:
Retrieve a session object across multiple requests to the same or different servlets within the same WebApp
Store objects into a session object
Retrieve objects from a session object
Respond to the event when a particular object is added to a session
Respond to the event when a session is created and destroyed
Expunge a session object
5.2 Given a scenario, state whether a session object will be invalidated.
5.3 Given that URL rewriting must be used for session management, identify the design requirements on sessionrelated HTML pages.
The document discusses implementing AJAX and JSON in ColdFusion 7 to dynamically load data when adding classes in an online training system. It describes how AJAX allows asynchronous retrieval of data from the server using JavaScript to avoid loading all data at page load. JSON is used to convert ColdFusion data structures to a lightweight format for transferring via AJAX calls. A case study demonstrates loading instructor, classroom and equipment details only when needed rather than on initial page load to improve performance.
This document discusses web scraping using PHP. It provides an overview of HTTP requests like GET and POST, libraries for making requests like cURL and PEAR HTTP Client, parsing responses, and best practices for web scraping applications.
Building Better Applications with Data::ManagerJay Shirley
The document discusses tools for managing form data and validation. It introduces Data::Manager, which provides a way to manage incoming data and validation rules across multiple scopes or sections. Data::Manager uses Data::Verifier under the hood to validate data according to defined rules. It provides methods to verify data, check for errors, and retrieve validation results. The document emphasizes usability, reliability, and hiding complexity through a clean API.
This document provides an overview of software security best practices and common vulnerabilities for Odoo code. It discusses the top 10 risks including injection, broken authentication, sensitive data exposure, XML external entities, broken access control, security misconfiguration, cross-site scripting, insecure deserialization, vulnerable components, and insufficient logging. For each risk, it provides examples of vulnerable code and recommendations for more secure implementations. It emphasizes that the Odoo framework includes mechanisms to prevent many mistakes but knowledge and mindset are also key. The document concludes with recommendations for code reviews to check access control, permissions, templates, evaluations, injections, and cross-site scripting prevention.
This document discusses CGI programming and HTTP cookies. It provides an overview of CGI and how it is used to send data to servers via the GET and POST methods. It also explains how templates can be used to dynamically generate web pages. Finally, it covers HTTP cookies in detail, including how they are delivered, valid parameters for setting cookies, the different types (persistent and non-persistent), and how they are stored on a user's device.
The document discusses GET and POST methods in PHP. GET retrieves data from forms by sending name-value pairs in the URL, while POST sends data invisibly within the request. GET has limits on data size and is less secure, while POST has no size limits and is more secure. Both populate the $_GET and $_POST superglobals in PHP. The $_REQUEST variable contains data from GET, POST, and cookies to retrieve form data regardless of submission method.
The document discusses PHP security best practices. It emphasizes two golden rules: 1) filter all external input and 2) escape all output. It provides examples of filtering user-submitted data and escaping it before displaying to browsers or inserting into databases. It also covers common attacks like SQL injection, session hijacking, and cross-site scripting, explaining how to prevent them by following the two golden rules of filtering input and escaping output.
12-security.ppt - PHP and Arabic Language - Indexwebhostingguy
The document discusses PHP security best practices. It emphasizes two golden rules: 1) filter all external input and 2) escape all output. It provides examples of filtering user-submitted data and escaping it before displaying or inserting into a database. It also covers common attacks like SQL injection, session fixation, and cross-site scripting, explaining how to prevent them by following the two golden rules of filtering input and escaping output.
This document provides information on handling PHP forms. It discusses how the $_GET and $_POST superglobals are used to collect form data via the GET and POST methods. It provides an example of a simple HTML form and how to display submitted data using $_GET and $_POST. It discusses when to use GET vs POST and how to validate form data with PHP to protect against malicious code. It also covers required fields, validating email addresses and URLs, and keeping form values populated after submission. The document is intended to guide readers through processing PHP forms securely and with validation.
The document discusses the servlet model and how servlets handle HTTP requests and responses. Some key points:
- Servlets use doXXX methods like doGet, doPost to handle different HTTP request methods. These methods receive a request and response object to access data and send a response.
- The request object provides access to parameters, headers, and attributes while the response object sets headers and content type for the response.
- Sessions allow servlets to access user data across multiple requests using attributes. Cookies can also be used to manage sessions between the client and server.
JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. It is used primarily to transmit data between a server and web application. JSON is language independent, lightweight and easy to read/write. It is used to transmit structured data over network connections, by web services and APIs to provide public data.
07 application security fundamentals - part 2 - security mechanisms - data ...appsec
This document discusses data validation concepts and best practices. It covers four core concepts: 1) whitelisting and blacklisting known good/bad values, 2) validating data length and format, 3) validating data before use in SQL, eval functions, or writing to buffers, and 4) encoding output to prevent XSS. Real world examples demonstrate how failing to validate data can enable SQL injection, XSS attacks, buffer overflows, and more. The document advocates restricting input length, whitelisting valid characters, encoding output, and using safe functions like strncpy() to avoid security issues.
This document discusses PHP arrays and superglobal variables. It explains that arrays allow the collection of related elements in a single variable and allow access, iteration, addition and removal of elements. Array keys can be integers or strings and do not need to be sequential. Multidimensional arrays are also covered. The document then discusses PHP superglobal variables like $_GET, $_POST and $_SERVER that provide access to form data and server information. It provides examples of accessing submitted form data and server variables. Object-oriented programming in PHP including classes, objects, inheritance and interfaces is also summarized.
1.1 For each of the HTTP methods,GET,POST, andPUT, identifythe corresponding method in the HttpServletclass.
1.3 For each of the following operations, identify the interfaceand method name that should be used:
Retrieve HTML form parameters from the request
Retrieve a servlet initialization parameter
Retrieve HTTP request header information
Set an HTTP response header
set the content type of the response
Acquire a text stream for the response
Acquire a binary stream for the response
Redirect an HTTP request to another URL
1.4 Identify the interface and method to access values and resources and to set object attributes within the following three web scopes:
Request
Session
Context
1.5 Given a life-cycle method: init,service , or destroy, identify correct statements bout its purpose or about how and when it is invoked.
1.6 Use a RequestDispatcher to include or forward to a web resource.
The document discusses various aspects of building a web application using Java including HTML forms, handling form data with servlets and requests/responses, connecting to a database using MySQL and its Java connector library, using the MVC pattern to manage database requests, and implementing user authentication with a login servlet that verifies credentials against a users table.
5.1 Identify the interface and methods for each of the following:
Retrieve a session object across multiple requests to the same or different servlets within the same WebApp
Store objects into a session object
Retrieve objects from a session object
Respond to the event when a particular object is added to a session
Respond to the event when a session is created and destroyed
Expunge a session object
5.2 Given a scenario, state whether a session object will be invalidated.
5.3 Given that URL rewriting must be used for session management, identify the design requirements on sessionrelated HTML pages.
The document discusses implementing AJAX and JSON in ColdFusion 7 to dynamically load data when adding classes in an online training system. It describes how AJAX allows asynchronous retrieval of data from the server using JavaScript to avoid loading all data at page load. JSON is used to convert ColdFusion data structures to a lightweight format for transferring via AJAX calls. A case study demonstrates loading instructor, classroom and equipment details only when needed rather than on initial page load to improve performance.
This document discusses web scraping using PHP. It provides an overview of HTTP requests like GET and POST, libraries for making requests like cURL and PEAR HTTP Client, parsing responses, and best practices for web scraping applications.
Building Better Applications with Data::ManagerJay Shirley
The document discusses tools for managing form data and validation. It introduces Data::Manager, which provides a way to manage incoming data and validation rules across multiple scopes or sections. Data::Manager uses Data::Verifier under the hood to validate data according to defined rules. It provides methods to verify data, check for errors, and retrieve validation results. The document emphasizes usability, reliability, and hiding complexity through a clean API.
This document provides an overview of software security best practices and common vulnerabilities for Odoo code. It discusses the top 10 risks including injection, broken authentication, sensitive data exposure, XML external entities, broken access control, security misconfiguration, cross-site scripting, insecure deserialization, vulnerable components, and insufficient logging. For each risk, it provides examples of vulnerable code and recommendations for more secure implementations. It emphasizes that the Odoo framework includes mechanisms to prevent many mistakes but knowledge and mindset are also key. The document concludes with recommendations for code reviews to check access control, permissions, templates, evaluations, injections, and cross-site scripting prevention.
This document discusses CGI programming and HTTP cookies. It provides an overview of CGI and how it is used to send data to servers via the GET and POST methods. It also explains how templates can be used to dynamically generate web pages. Finally, it covers HTTP cookies in detail, including how they are delivered, valid parameters for setting cookies, the different types (persistent and non-persistent), and how they are stored on a user's device.
The document discusses GET and POST methods in PHP. GET retrieves data from forms by sending name-value pairs in the URL, while POST sends data invisibly within the request. GET has limits on data size and is less secure, while POST has no size limits and is more secure. Both populate the $_GET and $_POST superglobals in PHP. The $_REQUEST variable contains data from GET, POST, and cookies to retrieve form data regardless of submission method.
The document discusses PHP security best practices. It emphasizes two golden rules: 1) filter all external input and 2) escape all output. It provides examples of filtering user-submitted data and escaping it before displaying to browsers or inserting into databases. It also covers common attacks like SQL injection, session hijacking, and cross-site scripting, explaining how to prevent them by following the two golden rules of filtering input and escaping output.
12-security.ppt - PHP and Arabic Language - Indexwebhostingguy
The document discusses PHP security best practices. It emphasizes two golden rules: 1) filter all external input and 2) escape all output. It provides examples of filtering user-submitted data and escaping it before displaying or inserting into a database. It also covers common attacks like SQL injection, session fixation, and cross-site scripting, explaining how to prevent them by following the two golden rules of filtering input and escaping output.
Similar to Working with Data and built-in functions of PHP (20)
🔥🔥🔥🔥🔥🔥🔥🔥🔥
إضغ بين إيديكم من أقوى الملازم التي صممتها
ملزمة تشريح الجهاز الهيكلي (نظري 3)
💀💀💀💀💀💀💀💀💀💀
تتميز هذهِ الملزمة بعِدة مُميزات :
1- مُترجمة ترجمة تُناسب جميع المستويات
2- تحتوي على 78 رسم توضيحي لكل كلمة موجودة بالملزمة (لكل كلمة !!!!)
#فهم_ماكو_درخ
3- دقة الكتابة والصور عالية جداً جداً جداً
4- هُنالك بعض المعلومات تم توضيحها بشكل تفصيلي جداً (تُعتبر لدى الطالب أو الطالبة بإنها معلومات مُبهمة ومع ذلك تم توضيح هذهِ المعلومات المُبهمة بشكل تفصيلي جداً
5- الملزمة تشرح نفسها ب نفسها بس تكلك تعال اقراني
6- تحتوي الملزمة في اول سلايد على خارطة تتضمن جميع تفرُعات معلومات الجهاز الهيكلي المذكورة في هذهِ الملزمة
واخيراً هذهِ الملزمة حلالٌ عليكم وإتمنى منكم إن تدعولي بالخير والصحة والعافية فقط
كل التوفيق زملائي وزميلاتي ، زميلكم محمد الذهبي 💊💊
🔥🔥🔥🔥🔥🔥🔥🔥🔥
How to Setup Default Value for a Field in Odoo 17Celine George
In Odoo, we can set a default value for a field during the creation of a record for a model. We have many methods in odoo for setting a default value to the field.
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...EduSkills OECD
Andreas Schleicher, Director of Education and Skills at the OECD presents at the launch of PISA 2022 Volume III - Creative Minds, Creative Schools on 18 June 2024.
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
Gender and Mental Health - Counselling and Family Therapy Applications and In...PsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
2. Validate input field in the HTML Form
• To validate the form using HTML, we will use the HTML
<input> required attribute.
• The <input> required attribute is a Boolean attribute
that is used to specify the input element that must be
filled out before submitting the Form.
3. Data validation ensures accurate and useful user input. It
checks for completed required fields, valid dates, and
appropriate data types.
• Required Fields: Users must fill in all mandatory fields
to avoid incomplete submissions.
• Date Validation: Ensures users enter dates in the correct
format.
• Numeric Field Text: Verifies users enter text in text
fields and numeric values in numeric fields.
4. Validation takes place either on the server side (after data
submission) or on the client side (prior to data submission).
• Server-side: Done by the web server for data integrity and
security.
• Client-side: Performed by the browser for instant user feedback.
8. Pass values of variables between pages in site. These are
required in many different ways. Some time we collect some
value from a database and want to retain the value for the
particular user throughout the site as the user moves
between pages. There are different ways for passing such
values of the variables.
9. Passing variable values between pages using
session
This is one of the secured ways the variables are passed between
pages. The best example of such a system is when we see our user-
id inside a member area after we logged in. In a member login
system the user details are verified and once found correct, a new
session is created and with user id of the member and this value is
stored at server end. Every time a new page is opened by the
browser, the server checks the associated session value and display
the user id. This system is more secure and the member doesn't get
any chance to change the values.
10. Passing variables between pages using cookies
Cookies are stored at the user or the client end and values can be
passed between pages using PHP. But here the client browser can
reject accepting cookies by changing the security settings of the
browser. So this system can fail to pass values between pages if user
or client end settings are changed. But cookies are quit useful in
handling user entered values and passing them between pages.
11. Passing variables between pages using URL
Pass variable values between pages through the URL ( in address bar
of the browser). Here values are visible to the user and others as
they appear in the address bar and also in the browser history. This
is not a secure way to transfer sensitive data like password, etc.
12. Advantage of using URL to pass variables
• The advantage is we can pass data to a different site even running
at different servers. Any scripting language like ASP, JSP, PHP
• Easy to save the URL or bookmark it for frequent use.
• Copy the URL and send it to a friend to refer.
13. Example of passing data through URL within a site.
<a href='page2.php?id=2489&user=tom'>link to page2</a>
When the above link is clicked, page2.php gets the
variables id and user with data 2489 and tom respectively.
Code to collect data in PHP.
echo $_GET['id']; // output 2489
echo $_GET['user']; // output tom
14. Passing data outside
<a href=https://www.sitename.com/index.php?id=2489&user=tom>Link to
another site</a>
Note that after the page name we are using question mark ( ? ) to start
the variable data pair and we are separating each variable data pair
with one ampersand ( & ) mark.
15. Submitting form values through GET method
A web form when the method is set to GET method, it submits the
values through URL. So we can use one form to generate an URL
with variables and data by taking inputs from the users. The form
will send the data to a page within the site or outside the site by
formatting a query string.
<form method=GET action='https://www.anysite.com/index.php'>
16. Submitting a form through POST method
By post method of form submission we can send more number or
length of data. Sensitive information like password does not get
exposed in URL by POST method, so our login forms we should use
POST method to submit data. This is how we collect data submitted
by POST method in PHP
$id=$_POST['id'];
$password=$_POST['password'];
17. Difference between GET and POST
Issues GET POST
Browser History Data remain in Browser History Data Not available in Browser
History
Bookmark URL with Data can be
bookmarked
No data is available in URL to
bookmark the page
Data Length Restriction The restriction (of URL ) is
applicable
No Restriction
cached Can be cached No meaningful caching
Sensitive Data Data like password , pin etc. are
exposed through URL so they
should not be passed using GET
method
Better than GET method as data
is not exposed through URL
18. Collecting data submitted by either GET or
POST method
If a page is receiving a data which can come in any one of the
method GET or POST then how to collect it ? Here we are not sure
how to collect the data. So we will use like this.
$id=$_REQUEST['id'];
$password=$_REQUEST['password'];
19. PHP - $_REQUEST
$_REQUEST
$_REQUEST is a PHP super global variable which contains submitted
form data, and all cookie data.
In other words, $_REQUEST is an array containing data from $_GET,
$_POST, and $_COOKIE.
You can access this data with the $_REQUEST keyword followed by
the name of the form field, or cookie, like this:
$_REQUEST['firstname']
20. String Function chr()
• It is used to return a character from a specified ASCII value
• The PHP chr() function is used to generate a single byte string
from a number. In another words we can say that it returns a
character from specified ASCII value.
• Syntax:
string chr ( int $bytevalue );
21. Example 1:
<?php
$char =52;
echo "Your character is :".$char;
echo "<br>"."By using 'chr()' function your value is: ".chr($char);// d
ecimal Value
?>
• Your character is : 52 By using 'chr()' function your value is: 4
22. Example 2:
<?php
$char =052;
echo "Your character is :".$char;
echo "<br>"."By using 'chr()' function your value is: ".chr($char); // O
ctal Value
?>
• Your character is :42 By using 'chr()' function your value is: *
23. <?php
echo "Your character is :0x52";
echo "<br>"."By using 'chr()' function your value is: ".chr(0x52); // H
ex value
?>
• Your character is :0x52
By using 'chr()' function your value is: R
24. ord()
• Returns the ASCII value of the first character of a string.
Definition and Usage
The ord() function returns the ASCII value of the first character of a
string.
Syntax:
ord(string)
<?php
echo ord("h")."<br>";
echo ord("hello")."<br>";
?>
O/P:
104
104
26. • strtoupper()
• Convert all characters to uppercase:
<?php
echo strtoupper("Hello WORLD!");
?>
HELLO WORLD
27. • lcfirst() - converts the first character of a string
to lowercase
• ucfirst() - converts the first character of a string
to uppercase
• ucwords() - converts the first character of each
word in a string to uppercase
33. ltrim() -
Removes whitespace or other characters from the
left side of a string
Definition and Usage
The ltrim() function removes whitespace or other predefined
characters from the left side of a string.
Related functions:
•rtrim() - Removes whitespace or other predefined characters
from the right side of a string
•trim() - Removes whitespace or other predefined characters
from both sides of a string
34. • Syntax
ltrim(string,charlist)
• string
Required. Specifies the string to check
• charlist
Optional. Specifies which characters to remove from the string. If
omitted, all of the following characters are remove
"0" - NULL
"t" - tab
"n" - new line
"x0B" - vertical tab
"r" - carriage return
" " - ordinary white space
35. • Remove newlines (n) from the left side of a string:
• <?php
$str = "nnnHello World!";
echo "Without ltrim: " . $str;
echo "<br>";
echo "With ltrim: " . ltrim($str);
?>
38. The strcmp() function compares two strings.
• The strcmp() function compares two strings.
• Note: The strcmp() function is binary-safe and case-sensitive.
• Tip: This function is similar to the strncmp() function, with the
difference that you can specify the number of characters from
each string to be used in the comparison with strncmp().
Syntax
strcmp(string1,string2)
39. Return Value
<!DOCTYPE html>
<html>
<body>
<?php
echo strcmp("Hello world!","Hello world!")."<br>"; // the two strings are equal
echo strcmp("Hello world!","Hello")."<br>"; // string1 is greater than string2
echo strcmp("Hello world!","Hello world! Hello!")."<br>"; // string1 is less than
string2
?>
</body>
</html>
o/p:
0
7
-7
This function returns: 0 - if the two strings are equal
<0 - if string1 is less than string2
>0 - if string1 is greater than string2
40. strpos() - Search For a Text Within a String
• The PHP strpos() function searches for a specific text
within a string. If a match is found, the function returns
the character position of the first match. If no match is
found, it will return FALSE.
Example
Search for the text "world" in the string "Hello world!":
<?php
echo strpos("Hello world!", "world"); // outputs 6
?>
41. Replace Text Within a String
The PHP str_replace() function replaces some characters
with some other characters in a string.
Example
Replace the text "world" with "Dolly":
<?php
echo str_replace("world", "Dolly", "Hello world!"); // outputs
Hello Dolly!
?>
42. str_word_count() - Count Words in a String
The PHP str_word_count() function counts the number of words in
a string.
Example
Count the number of word in the string "Hello world!":
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
43. Math functions
•PHP provides many predefined math
constants and functions that can be used to
perform mathematical operations.
45. Abs()
• The abs() function returns the absolute (positive) value of a
number.
Syntax:
abs( value )
Parameters: The abs() function accepts single parameter value
which holds the number whose absolute value you want to find.
Return Value: It returns the absolute value of the number passed to it
as argument.
• number Required. Specifies a number. If the number is of type
float, the return type is also float, otherwise it is integer
46. • The abs() function in PHP is identical to what we call modulus in
mathematics. The modulus or absolute value of a negative number
is positive.
48. Ceil()
• The ceil() function rounds a number UP to the nearest integer.
Syntax:
float ceil(value)
• Parameters: The ceil() function accepts a single parameter value
which represents the number which you want to round up to the
nearest greater integer.
• Return Value: The return type of the ceil() function is float as
shown in the syntax. It returns the number which represents the
value rounded up to the next highest integer.
• number Required. Specifies the value to round up
50. Floor()
• The floor() function rounds a number DOWN to the nearest
integer.
Syntax:
float floor(value)
• Parameters: This function accepts the single parameter value
which is rounded down to the next lowest integer.
• Return Value: The return type is a float value. It returns the next
lowest integer value as a float which is rounded down, only if
necessary.
• number Required. Specifies the value to round down
52. Round()
• The round() function rounds a floating-point number.
• Syntax:
round(number,precision,mode);
• Parameters: It accepts three parameters out of which one is compulsory
and two are optional. All of these parameters are described below:
• $number: It is the number which you want to round.
• $precision: It is an optional parameter. It specifies the number of
decimal digits to round to. The default value of this parameter is zero.
• $mode: It is an optional parameter. It specifies a constant to specify the
rounding mode.
• number Required. Specifies the value to round precision
• Optional. Specifies the number of decimal digits to round to. Default
is 0
53. Round()
• The round() function rounds a floating-point number.
• Syntax:
round(number,precision,mode);
• Parameters: It accepts three parameters out of which one is compulsory
and two are optional. All of these parameters are described below:
• $number: It is the number which you want to round.
• $precision: It is an optional parameter. It specifies the number of
decimal digits to round to. The default value of this parameter is zero.
• $mode: It is an optional parameter. It specifies a constant to specify the
rounding mode.
• number Required. Specifies the value to round precision
• Optional. Specifies the number of decimal digits to round to. Default
is 0
54. • mode Optional. Specifies a constant to specify the
rounding mode: PHP_ROUND_HALF_UP - Default. Rounds
number up to precision decimal, when it is half way
there. Rounds 1.5 to 2 and -1.5 to -2
• PHP_ROUND_HALF_DOWN - Round number down to
precision decimal places, when it is half way there.
Rounds 1.5 to 1 and -1.5 to -1
• PHP_ROUND_HALF_EVEN - Round number to precision
decimal places towards the next even value
• PHP_ROUND_HALF_ODD - Round number to precision
decimal places towards the next odd value
58. Fmod()
• The fmod() function returns the remainder (modulo) of x/y.
• In PHP the fmod() function is used to calculate the Modulo of any
division which may contain floats as both dividends and divisors.
Syntax:
float fmod ($dividend, $divisor)
• Parameters: The function takes two parameters as follows:
• $dividend: This parameter takes a float which is to be divided.
• $divisor: This parameter takes a float which is to be used as a
divisor.
• Return Type: This function returns a Floating-point remainder of
the division.
60. Min ()
• The min() function returns the lowest value in an array, or the lowest
value of several specified values.
• The min() function can take an array or several numbers as an argument
and return the numerically minimum value among the passed
parameters. The return type is not fixed, it can be an integer value or a
float value based on input.
• Sytax:
min(array_values);
or
min(value1,value2,...);
• Parameters: This function accepts two different types of parameters
which are explained below:
• array_values : It specifies an array containing the values.
• value1, value2, … : It specifies two or more than two values to be
compared.
62. Max()
• The max() function returns the highest value in an array, or the highest value of
several specified values.
• The max() function of PHP is used to find the numerically maximum value in an
array or the numerically maximum value of several specified values.
• The max() function can take an array or several numbers as an argument and return
the numerically maximum value among the passed parameters. The return type is
not fixed, it can be an integer value or a float value based on input.
• Sytax:
max(array_values);
or
max(value1,value2,...);
•
Parameters: This function accepts two different types of arguments which are
explained below:
• array_values : It specifies an array containing the values.
• value1, value2, … : It specifies two or more than two values to be compared.
64. Pow()
• The pow() function returns ($base raised to the power of $exp.
• Syntax:
number pow($base, $exp);
• Parameters : The pow() function accepts two parameters as
shown in the above syntax:
• $base : It is used to specify the base.
• $exponent : It is used to specify the exponent.
• Return Value: It returns a number (integer or floating-point)
which is equal to $base raised to the power of $exponent.
68. Rand()
• The rand() function generates a random integer.
• The rand() is an inbuilt function in PHP used to generate a random
number ie., it can generate a random integer value in the range [min,
max].
• rand();
or
rand(min,max);
• Parameter values:
• min: It is an optional parameter that specifies the lowest value that will
be returned. The default value is 0.
• max: It is an optional parameter that specifies the highest value to be
returned. The default value is getrandmax().
69. Examples:
Note: The output of the code may change every time it is run. So the
output may not match with the specified output.
<?php
// Generating a random number
$randomNumber= rand();
print_r($randomNumber);
print_r("n");
// Generating a random number in a
// Specified range.
$randomNumber= rand(15,35);
print_r($randomNumber);
?>
output:
1257424548
28
71. Array()
• The array() function is used to create a PHP array. This function
can be used to create indexed arrays or associative arrays. PHP
arrays could be single dimensional or multi-dimensional.
Syntax
Syntax to create PHP indexed arrays:
$a = array(value1, value2, value3, ...)
Syntax to create PHP associative arrays:
$a = array(key1 => value1, key2 => value2...)
73. Count()
• The count() function returns the number of elements in an
array.
Syntax
count(array, mode)
74.
75. in_array — Checks if a value exists in an array
• Syntax:
• in_array(search, array, type)
76. in_array example
• <?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
if (in_array("Glenn", $people))
{
echo "Match found";
}
else
{
echo "Match not found";
}
?>
• o/p: Match found
77. list() function
• The list() function is used to assign values to a list of variables in
one operation.
• Syntax:
• list(var1, var2, ...)
78. Example
• <?php
$my_array = array("Dog","Cat","Horse");
list($a, , $c) = $my_array;
echo "Here I only use the $a and $c variables.";
?>
• o/p:
Here I only use the Dog and Horse variables.
79. current() function
• Definition and Usage
• The current() function returns the value of the current element
in an array.
• Every array has an internal pointer to its "current" element,
which is initialized to the first element inserted into the array.
80. Related current methods:
• end() - moves the internal pointer to, and outputs, the last element in
the array
• next() - moves the internal pointer to, and outputs, the next element in
the array
• prev() - moves the internal pointer to, and outputs, the previous
element in the array
• reset() - moves the internal pointer to the first element of the array
• each() - returns the current element key and value, and moves the
internal pointer forward
Syntax:
current(array)
81. <?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is
Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first
element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current
element (now Joe), and moves the internal pointer forward
?>
Peter
Joe
Joe
Peter
Cleveland
Glenn
Glenn
Peter
Joe
Array ( [1] => Joe [value] => Joe [0] => 1 [key] => 1 )
82. PHP Include File
• The include (or require) statement takes all the text/code/markup
that exists in the specified file and copies it into the file that uses the
include statement.
• Including files is very useful when you want to include the same
PHP, HTML, or text on multiple pages of a website.
• It is possible to insert the content of one PHP file into another PHP
file (before the server executes it), with the include or require
statement.
• The include and require statements are identical, except upon
failure:
• require will produce a fatal error (E_COMPILE_ERROR) and
stop the script
• include will only produce a warning (E_WARNING) and the
script will continue
83. PHP include and require
• Including files saves a lot of work. This means that you can create
a standard header, footer, or menu file for all your web pages.
Then, when the header needs to be updated, you can only update
the header include file.
Syntax
• include 'filename';
or
require 'filename';
84. Advantage
• Code Reusability: By the help of include and
require construct, we can reuse HTML code or
PHP script in many PHP scripts.
86. PHP Functions
• PHP function is a piece of code that can be reused many times.
• It can take input as argument list and return value.
• There are thousands of built-in functions in PHP.
87.
88.
89.
90.
91. Parameterized Function
• PHP Parameterized functions are the functions with
parameters. You can pass any number of parameters
inside a function. These passed parameters act as
variables inside your function.
• They are specified inside the parentheses, after the
function name.
• The output depends upon the dynamic values passed as
the parameters into the function.
96. PHP Superglobals
PHP provides an additional set of predefined arrays
containing variables from the web server the
environment, and user input. These new arrays are
called superglobals.
97. $GLOBALS
Contains a reference to every variable which is
currently available within the global scope of the
script. The keys of this array are the names of the
global variables.
99. $_SERVER
• This is an array containing information such as
headers, paths, and script locations.
• The entries in this array are created by the web
server.
• There is no guarantee that every web server will
provide any of these.
102. $_POST
• An associative array of variables passed to the
current script via the HTTP POST method.
103. $_REQUEST
• An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.
• <!DOCTYPE html>
<html>
<body>
<form method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = htmlspecialchars($_REQUEST['fname']);
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
104. $_PHP_SELF
• A string containing PHP script file name in which it is called.
$_SERVER['PHP_SELF']
• The filename of the currently executing script, relative to the
document root
$_SERVER['SERVER_NAME']
• The name of the server host under which the current script is
executing. If the script is running on a virtual host, this will be the
value defined for that virtual host.