My site lists pages from mysq using php, if i remove a record from the database I then want that to be 301, but at the moment it just displays a default error message. The code for the error is this
if (empty($name)) return $this->Error('Error: Invalid Page!');
How can I change this to 301 and so remove from search engines
The Error() function has to be somewhere in you system, otherwise it can’t be executed. It’s definitely not a part of the PHP core.
Beside from that, 301 is really the wrong code to use here.
301 is for Moved permanently, but for the scenario you’re describing the content is REmoved permanently, which is something else entirely, and the website should reply with a 404 Not Found (which I’m guessing is what the Error() function does).
Yes. Moved Permanently isn’t the same as REMoved Permanently. You are expected to provide the location where the resource moved to with a 301 redirect.
The error function looks like it handles lots of different types of error, not just 404, so you’d need something in there to tell you it is a 404 error you want to generate to start with. Once you know it’s a 404 error, you can use the header() function to set the 404 header.