开发者

Javascript redirect vs form submit to a php script

I've got a form on my websites homepage that contains a box for a user to enter a members name. From there the form currently submits to a PHP script which just calls Header('Location: blah); and then directs them to /search/username/.

开发者_开发百科Would it be worth it (i'm assuming so) doing that redirection in javascript so that directs them straight to /search/username? If so how would I go about redirecting with javascript, just plain old window.location = "http://www.google.com/"


Server side is always better method as it's more difficult to bypass than client side method. Be sure to add exit function after redirection using header.

ob_clean();
header('Location: target.php');
exit();


To do it in JavaScript, you could:

<input id="username" type="text" onclick="" />
<input type="button" onclick="window.location='/search/'+document.getElementById('username').value" />

You could add some validation to the event as well.

Would it be worth it

That depends on your specific situation. If your server is getting 100's of these requests a second, then sure. Otherwise, it really doesn't matter which way you do it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜