How can we avoid my php form from hacking?

0 votes
I wanted to know how can i  avoid $_SERVER["PHP_SELF"]  from exploits?
Feb 13 in PHP by kartik
• 27,140 points
208 views

1 answer to this question.

0 votes

Hii @kartik,

If you want to know php from can led to vulnerability check it out- PHP Form Security

  $_SERVER["PHP_SELF"] exploits can be avoided by using the htmlspecialchars() function.

The form code should look like this:

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

The htmlspecialchars() function converts special characters to HTML entities. Now if the user tries to exploit the PHP_SELF variable, it will result in the following output:

<form method="post" action="test_form.php/&quot;&gt;&lt;script&gt;alert('hacked')&lt;/script&gt;">

The exploit attempt fails, and no harm is done!

answered Feb 13 by Niroj
• 58,500 points

Related Questions In PHP

0 votes
1 answer

How can we track Google Analytics on a redirection page with PHP?

Hello @kartik, Since the page that is sending ...READ MORE

answered Apr 29 in PHP by Niroj
• 58,500 points
104 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13 in PHP by Niroj
• 58,500 points
177 views
0 votes
1 answer

How to validate E-mail and URL of Php form?

hey, The code below shows a simple way ...READ MORE

answered Feb 13 in PHP by manish
168 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27 in PHP by Niroj
• 58,500 points
93 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20 in Web Development by Niroj
• 58,500 points

edited Jan 21 by Niroj 125 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13 in PHP by Niroj
• 58,500 points
246 views
0 votes
1 answer

How to shrink Navigation menu or bar on Scroll?

Hey, You can follow the steps below in ...READ MORE

answered Feb 19 in PHP by varun
1,014 views
0 votes
1 answer

How to reload or re-render the entire page using AngularJS?

Hello @kartik< For the record, to force angular ...READ MORE

answered Jul 15 in Node-js by Niroj
• 58,500 points
41 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 58,500 points
81 views
0 votes
1 answer

How can we create a session in PHP?

Hello @kartik, session_start() function is used in PHP to ...READ MORE

answered Mar 27 in PHP by Niroj
• 58,500 points
71 views