MyBB Community Forums

Full Version: A PHP question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Currently on my site, when a user types an url incorrectly they are re-directed to www.mysite.net/errors/404.php.

This is annoying for the user who has to re-type the whole url from scratch.

I would like it so that when a user experiences one of my error pages, the url in their address remains the one that has been requested, not that of my error page. Is that possible with PHP?

I'm guessing that I am going to need something with $uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] but afterwards I'm stuck, and that's probably completely wrong anyway.

Thanks for your help.
I am not sure the way you have the error page setup, but when I create an 404 error page using .htaccess I have this:

ErrorDocument 404 /path/to/404

and if I was to type a page that doesn't exist, it would display the error page but remain at the same url.

Have you got it setup different than the way I do?
I had the full url instead of the path:
ErrorDocument 404 http://mysite.net/errors/404.php

But now I have changed it to how you have it and it works perfectly. Thanks
If it's a form give this a whirl and don't forget to add SafeAddSlashes to prevent sql injections:
<?php
if(isset($_POST['submit'])) {

$fieldname1= $_POST['fieldname1'];
if ($fieldname1 =="")
{
echo 'custom error message';
return;
}
$fieldname2 = $_POST['fieldname2'];
if ($fieldname2 =="")
{
echo 'custom error message';
return;
}

If your talking about the apache error messages, you can modify them from the /installeddirectory/httpd/errors directory. If your with a hosting company, they should have a feature where you can modify them, and have them redirect to the desired page using this:
        
<meta http-equiv="refresh" content="0; url=http://www.url.com">
Long story short, the Apache engine should have the url they typed included in the error message.
Kind Regards.
mysql_real_escape_string is generally safer than adding slashes.
blueparukia Wrote:mysql_real_escape_string is generally safer than adding slashes.
Wouldn't it be used for query's not forms?
It can be used for anything really. You will need a connection to a database to use it though.
mysql_real_escape_string takes into account the current encoding, whereas addslashes doesn't, which is why the former is safer. However, since it takes into account the DB encoding, a connection the DB is required so that it knows what to escape for.
mysql_real_escape_string also uses '' instead of \' which is generally safer in MySQL syntax
Ah, thanks for your considerations guys.
Kind Regards.