Use $_POST vars after an 404 redirection

Hello everybody.

My web host doesn’t let me use the mod rewrite so i use a little trick to simulate url rewriting, by using the apache’s error 404.
But the problem is : How can I use my $_POST vars after the form validation (that redirects me on the same page through the ErrorDocument 404 in my .htaccess file, but without any $_POST vars) ?

Thanks for the help.

Is there really necessity to use error 404 handler? This is not good from seo perspective. Can’t you just redirect within php script?

If there is no solution for you other than using error 404, you can store $_POST variables in the cookie before redirect, and then read them from $_COOKIE array.

Thank you for your fast reply.

Well, how can I do (or at least simulate) url rewriting with just an php script ? I don’t think it is possible.
And according to your solution, the problem is I can’t store anything because as soon as I click on the submit button, apache redirects me with the error 404 and it erases all post vars.

Sorry, but I can not figure situation when one would need to redirect with 404 error document on form submission. Can you not process your $_POST within say submit.php and then redirect to the required page?
submit.php[php]<?php
// processing $_POST request
// …

// redirecting
header(‘Location: dest.html’);
?>[/php]

Apache is redirecting me, by my htaccess file :

ErrorDocument 404 /Blog/index.php

In that way, I can use url like “mysite.com/article/1/my-article.html” and my index.php file analyse the url and include the right page.

So when use my form (), apache redirects me to index.php erasing the posts vars.

Never mind, I founded a working solution whiche is not that bad; I modified my form :

<form action="post.php" method="post">

And in post.php :
[php]
//Stock my post vars into the session array
$_SESSION = $_POST;
//redirects me to the initial page (the form page), and i then use $_SESSION intead of $_POST to use my POST vars.
header('Location: '.$_SERVER[“HTTP_REFERER”]);[/php]

Thank you for your help, have a nice day.

Sponsor our Newsletter | Privacy Policy | Terms of Service