Search code examples
phpjavascripthttp-redirectpagespeed

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/"


Solution

  • 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();