What you need is to set the content type of the response to plain text instead of html:
header("Content-Type: text/plain");
Place this in the first line of your php code of the will do.
However, you won’t be able to set head tags in HTML, which means you will have to remove the title and script tag, etc. as they will be displayed as plain text and won’t be rendered.
EDIT: Your content is displayed by grabbing data through ajax, but you can simply just use one file of php and echo the ip out.
Problem :
I have built this small HTML file you can see here https://alterego.cc/mypublicip/ that returns your public IP. If you inspect the code of the page you can actually see the HTML in there, because that’s an HTML file of course
What I would actually like to achieve is something like this https://wtfismyip.com/text (from someone else) where if you inspect the code you can see it’s just a text file there. No additional tags or anything in particular
How could I achieve the same result?
I have tried a bit of everything but I always end up having some HTML code in there. In particular with DIV and innerText but no particular luck so far. I believe I am following the wrong approach and there is something I am missing
Thanks!
Comments
Comment posted by aynber
Output only what you want. If there’s HTML code, then it’s something you’ve added, or you’re using a template
Comment posted by Chris Haas
JavaScript needs a host on the client-side in order to render, no browser will execute pure JS on direct access. So if you tried this with JS you’d need some minimum HTML for it to work. So unless you want to have a button event on the page that opens a new document and writes into it, JS is probably not an option. Looking at just PHP then, just echo and exit. That’s it.
Comment posted by Amadan
@ChrisHaas Nitpick: Serverside JavaScript has been a thing for many years (mostly in form of Node.js). However, it is true that it is much easier to set up a PHP page than to host a Node.js page.
Comment posted by Chris Haas
@Amadan, that’s why I said client-side. Unless there’s a way for server-side JS to be delivered to the client without something to bootstrap the process (like a script tag)
Comment posted by vulnerable to XSS
Danger
Comment posted by mukkino
Thank you mate! Looks muck better now. I posted a new answer with some changes I did. I am almost there I hope