473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

php sees html input as a code

Hi everybody.I'm recently working with PHP and i've made a mini forum page(usable) and when I put it in test,I obviously used commas,periods and others, it treats those symbols as codes.And I think this would result an XSS vulnerablity when launched in the future.How can I prevent this from happening?
Dec 21 '15 #1
4 1632
Claus Mygind
571 512MB
Most likely you are not separating your php code from your html code. But there really is no way to answer your question because you did not show us your code. Would like to have been of more help.
Dec 21 '15 #2
Okay lemme just write a simple sample of the code.
Expand|Select|Wrap|Line Numbers
  1.  <form method="POST" action="<?php $_PHP_SELF ?> "> 
  2. <input name="test" /> 
  3. <input type="submit" /> 
  4. <form> 
  5.  
  6. <?php
  7.  
  8. $test = $_POST['test']; 
  9.  
  10. echo 'You wrote '.$test.'!'; 
  11.  
  12. ?> 
  13.  
  14.  
  15.  
Feb 1 '16 #3
Claus Mygind
571 512MB
Ok first a few minor errors in your code, but since it is just an example that does not really matter.

Exploitation of your code is not possible when the page is streamed out, because the periods and other PHP command codes you insert in your page are not streamed out to the client machine.

From your example
Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.  
  3. $test = $_POST['test']; 
  4.  
  5. echo 'You wrote '.$test.'!'; 
  6.  
  7. ?> 
the streamed out page would not include any of the php code
ie: echo, the single quotes, ., or even the variable $test.

The only thing the user would see and have access to would be
You wrote something where something is the content of the variable $test.

To exploit your page the hacker would have to inject some code into one of your input fields.

It may be helpful for you to read this link

PHP code is not exposed to the user like javaScript. So you have no concern here.
Feb 2 '16 #4
Dormilich
8,658 Expert Mod 8TB
notes:
- $_PHP_SELF, not sure where you get that, but if you copy it over from $_SERVER['PHP_SELF'] you have an XSS vulnerability. better use $_SERVER['SCRIPT_NAME']
- the self-closing tags (/>) are invalid in HTML, though browsers conveniently ignore that

and a personal preference, semantically it makes more sense to write the submit button as button (<button type="submit">…</button>). it has the advantage that you cannot confuse it with an input box and you have better control of the content (<input> only allows text, <button> allows HTML)
Feb 3 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: anonymou | last post by:
I have a portal-like site where I cannot use the @ Page validateRequest=false approach for bypassing HTML input because it would affect all pages of the site. Does anyone have a work-around for...
0
by: darren | last post by:
When using the html input file (input type=file), is there anyway to NOT have the file loaded on the server? I am only interested in using this control to browse to a file and then get the filename,...
2
by: Robin | last post by:
On an ASP.Net web page that has a HTML Input file control run on the server side, is there any setting that limits the size of the file that can be uploaded? Is there any validation code that runs...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
1
by: Owen Wong | last post by:
Please look at my newly written class. It is meant to be used to filter suspicious html input from an online html editor. I need help about 2 things: 1. Does it need to filter more things? Which I...
3
by: vishnu | last post by:
Hi, I am using HTML input file button to browse the file and just am updating the file name in sql server table.But now i want to browse the file from the remote file share path ..How can i...
2
by: RajasScripts | last post by:
Hi I need some guidance in sorting HTML input tag sorting.I am able to sort columns with out input tag and with dates.But the only problem is I am not able to sort a column which is text box with...
4
by: Chris | last post by:
Hi, i 'm experimenting with postback and i tried that with a button server control and an Html input button but with runat="server". The button server control causes a postback, but not the...
1
by: tariqahmedpak | last post by:
Hi to All I need to ask that i have HTML Input File Server Control on the page (ASP.NET 2.0) when i browse the file and then in the code behind when i try to apply method HasFile it gives false...
3
by: coolnags | last post by:
Hi, I have created 2 html input text boxes with readonly property set to 'readonly'. I am handling the esc key event(27) in javascript code. When I press the esc key for the first time it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.