开发者

Server side validation php

I am trying to validate my page server side in php...to do that I have to do post to same pa开发者_如何学Pythonge in order to check the controls values. But after validation succeeds, how do i redirect to another page using post method? I can accomplish this using get But is there a way out to redirect page using post method from with the in the code itself?

In simple words I am trying to look for a solution to redirect my page using post method but from with my php code and not setting the action attribute in form tag.

Thanks,

Rizwan


Redirecting to another page from your PHP code, when you want to GET the new page:

<?php
  header("HTTP/1.1 303 See Other"); 
  header("Location: http://www.example.com/page/to/redirect-to.html");
?>

I'm using 303 here, as the HTTP/1.1 spec says:

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.

and redirecting using 301, 302 or 307 doesn't always get you a redirect-to-GET.


<form action="<?php echo $_SERVER['PHP_SELF']; ?> action="post">

... rest of form code

for your submit button

<input type="submit" name="formsubmit" value="submit button text" />

Somewhere towards the top of your page

<?php 
if(isset($_POST['formsubmit))
{
  //do validation and if validated - redirect to new page
}
  else {
 // display errors and current page with form again
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜