arunpatal Posted April 8, 2014 Share Posted April 8, 2014 <script> function check_field(){ document.getElementById("guest_form").submit() } </script> <?php if (isset($_POST["name"]) AND $_POST["name"] = "name"){ header("location:page.php"); } ?> <form method="post" id="guest_form"> <input type="text" value="abc" name="name" /> <input type="button" value="Sub" onclick="check_field()" id="aa" /> </form> When am running this code on my pc (xampp), It is running fine. But when i upload the file on server (godaddy)..... it does not redirect....... or the header is not working Quote Link to comment https://forums.phpfreaks.com/topic/287602-header-not-working/ Share on other sites More sharing options...
mac_gyver Posted April 8, 2014 Share Posted April 8, 2014 (edited) you cannot output ANYTHING to the browser before a header() statement. your javascirpt code is output that is being sent to the browser and cannot come before a header(), a session_start(), setcookie()... statement. the only reason this works on your development system is because php thought it would be fun to waste your time developing code that wouldn't run on every system. your development system has an output_buffer setting in the php.ini that should be turned off, so that code you develop will work, with regards to header() statements, on every system. stop and start your web server on your development system to get any change made to the php.ini to take effect. Edited April 8, 2014 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/287602-header-not-working/#findComment-1475351 Share on other sites More sharing options...
QuickOldCar Posted April 8, 2014 Share Posted April 8, 2014 (edited) should be a double == when checking against something, a single when setting if (isset($_POST['name']) AND $_POST['name'] == "name"){ in your post form you set the value as abc, so it should be this if (isset($_POST['name']) AND $_POST['name'] == "abc"){ Edited April 8, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/287602-header-not-working/#findComment-1475352 Share on other sites More sharing options...
arunpatal Posted April 8, 2014 Author Share Posted April 8, 2014 == is not a problem..... mac_gyver can you tell me the solution for this problem........ by giving example with the code above... Please Quote Link to comment https://forums.phpfreaks.com/topic/287602-header-not-working/#findComment-1475354 Share on other sites More sharing options...
Solution arunpatal Posted April 8, 2014 Author Solution Share Posted April 8, 2014 (edited) Adding ob_start(); solved the problem Edited April 8, 2014 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/287602-header-not-working/#findComment-1475360 Share on other sites More sharing options...
mac_gyver Posted April 8, 2014 Share Posted April 8, 2014 the single = in your posted code is a problem, because the conditional test will always be true if the post variable is set, regardless of the value in it. for your solution, i was hoping that you would rearrange the code on your page so that it was correctly organized as a web page. Quote Link to comment https://forums.phpfreaks.com/topic/287602-header-not-working/#findComment-1475392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.