Azu Posted November 11, 2007 Share Posted November 11, 2007 Hello.. how do I make PHP die INSTANTLY without sending any headers or anything? So that it will be like trying to access a URL that doesn't exist and says server not found? Quote Link to comment Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 exit. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 11, 2007 Share Posted November 11, 2007 or as you said.. die; Quote Link to comment Share on other sites More sharing options...
Azu Posted November 11, 2007 Author Share Posted November 11, 2007 Thanks doesn't work though. Quote Link to comment Share on other sites More sharing options...
Orio Posted November 11, 2007 Share Posted November 11, 2007 You mean that even if you have a situation like this one, both header won't be sent? Or only the first one? <?php header($header1); instantdie(); header($header2); ?> Orio. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted November 11, 2007 Share Posted November 11, 2007 the "page not found" you speak of is an apache (or other) server thing, not a PHP thing. die/exit both terminate the script at once. if you wish to replicate the not found page, you'll need to send a 404 header, which makes absolutely no difference to what is displayed but sends the correct header to the users browser/search engine bots, etc: <?php function die_404() { header("HTTP/1.1 404 Not Found"); echo '<h1>Page not Found</h1>'; die; } die_404(); ?> Quote Link to comment Share on other sites More sharing options...
Azu Posted November 11, 2007 Author Share Posted November 11, 2007 Server not found not page not found. Like if you try to open this link http://www.dj4jd9f5jgskjdfg346.com/ Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 11, 2007 Share Posted November 11, 2007 Since the browser's response to trying a link to a non-existent URL is different depending on the browser you use, it seems resonable to assume that the 'server not found' message is a browser feature and not a server feature. I guess that concludes this thread. Quote Link to comment Share on other sites More sharing options...
Azu Posted November 11, 2007 Author Share Posted November 11, 2007 Yes exactly that is what happens when it gets no response and it differs from browser to browser it's not something in the HTML. So please tell me how to make PHP die instantly without sending anything to the browser so that the browser reacts that way. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 11, 2007 Share Posted November 11, 2007 It can't. The instant your .php file is found by the server, check that... the instant the website ITSELF is found, your browser is aware of that. Then when your .php file is found, the server is going to generate green lights. The party is kind of exposed at this point, and just instructing your script to halt any further execution is not going to hide the fact that the server AND the script do in fact exist. PhREEEk Quote Link to comment Share on other sites More sharing options...
Azu Posted November 11, 2007 Author Share Posted November 11, 2007 You mean the server sends headers to the browser before it even interprets the page? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 11, 2007 Share Posted November 11, 2007 From my experience it's impossible to send a header with the 404 status code from within a PHP script (at least on an Apache server), because when a file is found, it's found. Likewise, you can't trick the server into not knowing about the script it's running. Quote Link to comment Share on other sites More sharing options...
Azu Posted November 11, 2007 Author Share Posted November 11, 2007 No I don't want to send any headers or anything else that says "this website exists". Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted November 11, 2007 Share Posted November 11, 2007 From my experience it's impossible to send a header with the 404 status code from within a PHP script (at least on an Apache server), because when a file is found, it's found. Likewise, you can't trick the server into not knowing about the script it's running. as i put earlier. works fine on any server that supports php. <?php function die_404() { header("HTTP/1.1 404 Not Found"); echo '<h1>Page not Found</h1>'; die; } die_404(); ?> Status codes like 404's are mainly useful for search engines, as they'll stop attempting to crawl the page in future. In terms of the original question - Azu, it's not possible. Quote Link to comment Share on other sites More sharing options...
Azu Posted November 12, 2007 Author Share Posted November 12, 2007 Okay thanks.. well if it's not possible to do it this way, is there another way to make a client think my server is offline? This is mainly for something I am making to try to automatically detect XSS attacks from E.G. automated tools and block them A.S.A.P. And the most secure response is no response so ya.. I thought that this was how I should do it.. Quote Link to comment Share on other sites More sharing options...
trq Posted November 12, 2007 Share Posted November 12, 2007 Okay thanks.. well if it's not possible to do it this way, is there another way to make a client think my server is offline? Block the request via your firewall. In iptables, a simple rule such as.... iptables -A INPUT -i eth0 -p tcp -s 203.0.178.211 --dport 80 -j DROP would suffice. This sends absolutely nothing back to the client and the browser will eventualy time out. Quote Link to comment Share on other sites More sharing options...
Azu Posted November 12, 2007 Author Share Posted November 12, 2007 Thanks.. the whole point of this though is to instantly block it as soon as it happens though.. and all I really want to do is just tell my website not to respond to the request. Not my whole computer just my PHP website. So I'm not sure why a firewall would be needed. Also this needs to be something OS independent (isn't that the whole point of PHP? ) Quote Link to comment Share on other sites More sharing options...
trq Posted November 12, 2007 Share Posted November 12, 2007 Thanks.. the whole point of this though is to instantly block it as soon as it happens though.. That rule will work as soon as its executed. and all I really want to do is just tell my website not to respond to the request. Not my whole computer just my PHP website. No, you actually want your server to not respond. The easiest (and maybe only) way to do so is to not let the request actually get to the server. Either way, if there is another solution to this problem, php isn't it. It happens far to far into the request to be able to do anything about it. Have a look through your servers documentation for another solution. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.