jdock1 Posted June 13, 2012 Share Posted June 13, 2012 Ok I am getting SO ANNOYED with the NOTORIOUS STUPID header error. All I am trying to do is use header location later in the page. There is absolutely NO php before it. None at all. Its just HTML, and at around line 200 I am trying to use header location to redirect to a page. Of course, I am getting the header error. I just dont understand WHY I cant use header location unless its before everything!? Im not even using any PHP except for the header location in that file!! I will never get the whole header thing. I dont care either. I just want to be able to use header location anywhere as long as Im not sending any cookies or anything before it. Is it even possible to use header location unless its on the first damn line!? Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/ Share on other sites More sharing options...
.josh Posted June 13, 2012 Share Posted June 13, 2012 You can have as much php as much as you want (as long as it doesn't output anything, like using echo). The HTML is the problem. In order to send headers you cannot have any output whatsoever before doing so. We have a sticky about header errors. Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353372 Share on other sites More sharing options...
Mahngiel Posted June 13, 2012 Share Posted June 13, 2012 Think about it logically. If you're going to use header() to perform a redirection, why are you even outputting anything on the page? You need to refocus your purpose. If you want to do something like ad sites do, where you have to stare at some ad for 5 seconds before a redirect, you should use javascript. Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353378 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 Ok really all I was trying to do is register a variable then redirect to the next page, kind of like a form would do. I guess its a pretty shoddy way to go about it. This is what IM doing, can anybody tell me an easier way to do it? Im not that new to PHP, I have been coding PHP for years now, I am just not a great thinker. This way is new to me because instead of using a form submit button I am using an image instead. So, my problem is I need to register $email which is $email = $_POST['paypal_email']; because the next page will need this variable in the URL. I have a form where the user enters their email and clicks a button to submit the form to get to the next page which is the URL with the email var. Here is the code: <?php $email = $_GET'paypal_email']; ?> <form action="" method="get"> <p><input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="paypal_email"></p> <p> </p> <input type="image" name="continue" src="images/arw_submit.png" alt="submit" value="Submit"></form></div> <?php if(@$_GET['continue'] == "Submit") { $email = $_POST['paypal_email']; header('Location: http://mysite.com/start.php?offer_pgid=071691&email=$email'); } ?> Thats what I was currently trying to do. Before, I just simply did this: <?php $email = $_POST['paypal_email']; ?> <form action="start.php?offer_pgid=071691&email=<?php echo $email;?>" method="post"> <p><input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="paypal_email"></p> <p> </p> <input type="image" name="continue" src="images/arw_submit.png" alt="submit" value="Submit"></form></div> And obviously, that didnt work because paypal_email was not registered yet before submitting the form. I think... I just never had this problem before for some reason? I have done this THOUSANDS of times before! Im really not this stupid guys, I just dont know, I cant think right now. Im sure I will kick myself in ass once I get the right code! Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353387 Share on other sites More sharing options...
antmeeks Posted June 13, 2012 Share Posted June 13, 2012 If all your trying to do is pass a value from one page to the next, you should do that in a SESSION var, not POST and definitely not GET. Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353393 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 If all your trying to do is pass a value from one page to the next, you should do that in a SESSION var, not POST and definitely not GET. Yeah, I would do that, but I need to capture their paypal email address which they fill out in a form that submits to the next page. For some reason it just isnt registering it. I think it could be because I am using an image as the input type, rather than a submit button. Idk, im really confused, I cant believe i am even having trouble doing this. I have done this so many times before IM just so lost. Its been a few months since I coded Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353402 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 13, 2012 Share Posted June 13, 2012 So the page looks for a submission via that input type="image" right? Why not have the form post to self (with the $_SERVER['php_self']) and place the redirect if statement prior to the HTML? Maybe I'm understanding the the issue here though. <?php $email = $_GET['paypal_email']; if(@$_GET['continue'] == "Submit") { $email = $_POST['paypal_email']; header('Location: http://mysite.com/start.php?offer_pgid=071691&email=$email'); } ?> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get"> <p><input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="paypal_email"></p> <p> </p> <input type="image" name="continue" src="images/arw_submit.png" alt="submit" value="Submit"></form></div> Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353404 Share on other sites More sharing options...
abdfahim Posted June 13, 2012 Share Posted June 13, 2012 //Sorry, message truncated. I didn't get your problem.// Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353405 Share on other sites More sharing options...
abdfahim Posted June 13, 2012 Share Posted June 13, 2012 you already are passing variable $_POST['paypal_email'] to start.php, why bother passing $_GET['email'] which is exactly same as $_POST['paypal_email']? if you need anyhow in GET format (which I don't know actually why), just assign in start.php like below $_GET['email'] = $_POST['paypal_email'] Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353406 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 So the page looks for a submission via that input type="image" right? Why not have the form post to self (with the $_SERVER['php_self']) and place the redirect if statement prior to the HTML? Maybe I'm understanding the the issue here though. <?php $email = $_GET['paypal_email']; if(@$_GET['continue'] == "Submit") { $email = $_POST['paypal_email']; header('Location: http://mysite.com/start.php?offer_pgid=071691&email=$email'); } ?> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get"> <p><input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="paypal_email"></p> <p> </p> <input type="image" name="continue" src="images/arw_submit.png" alt="submit" value="Submit"></form></div> Haha, wow, that could work. I am going to try it out. I will post back here. See, thats what I mean, I would have probably eventually came up with that, but sometimes I just get a complete "block" and can not think of any solution. There is always a solution and alternative way to do ANYTHING in PHP, thats what I love about it! //Sorry, message truncated. I didn't get your problem.// My problem is I was trying to get the variable $email to set before the form is submitted so it will post to a URL with the $email variable in the URL. Im just on some dumb shit right now! Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353407 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 you already are passing variable $_POST['paypal_email'] to start.php, why bother passing $_GET['email'] which is exactly same as $_POST['paypal_email']? if you need anyhow in GET format (which I don't know actually why), just assign in start.php like below $_GET['email'] = $_POST['paypal_email'] Idk. Like I said, Im just on some dumb stuff right now. I havent coded in a while and I think I have "writers block"! I really need to refresh my memory with my php reference book Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353409 Share on other sites More sharing options...
abdfahim Posted June 13, 2012 Share Posted June 13, 2012 good that you solved ur prob ... Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353410 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 Ok so its still not working. I tried using what HDfilmmaker suggested, but at first obviously php parsed header('Location: http://mysite.com/start.php?offer_pgid=071691&email=$email'); as email being $email instead of the variable data. So, I tried this: <?php if(@$_GET['continue'] == "Submit") { $email = $_POST['paypal_email']; header('Location: http://mysite.com/start.php?offer_pgid=071691&email='.$email.''); } ?> But it still didnt work, its redirecting me to the page but the variable $email is just not registering, it came up blank. WHY!??? WHY CANT I GET THIS!??!!! Its SO simple all I am trying to do is pass that variable to the next page!!! I think its becuse Im using an image input type instead of submit because I have NEVER had this problem before!!! Any help at all is GREATLY appreciated at this point! Thanks guys!! Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353414 Share on other sites More sharing options...
abdfahim Posted June 13, 2012 Share Posted June 13, 2012 can you just try using this code to make it basic (again if you want to use GET method anyhow in start.php? <form action="http://mysite.com/start.php?offer_pgid=071691" method="post"> <p><input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="paypal_email"></p> <p> </p> <input type="image" name="continue" src="images/arw_submit.png" alt="submit" value="Submit"></form> and write following line on top of start.php $_GET['email']=$_POST['paypal_email']; =========OR======= <form action="http://mysite.com/start.php" method="get"> <p><input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="email"></p> <p> </p> <input type="hidden" name="offer_pgid" value="071691"> <input type="image" name="continue" src="images/arw_submit.png" alt="submit" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353415 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 13, 2012 Share Posted June 13, 2012 Ok so its still not working. I tried using what HDfilmmaker suggested, but at first obviously php parsed header('Location: http://mysite.com/start.php?offer_pgid=071691&email=$email'); as email being $email instead of the variable data. So, I tried this: <?php if(@$_GET['continue'] == "Submit") { $email = $_POST['paypal_email']; header('Location: http://mysite.com/start.php?offer_pgid=071691&email='.$email.''); } ?> But it still didnt work, its redirecting me to the page but the variable $email is just not registering, it came up blank. WHY!??? WHY CANT I GET THIS!??!!! Its SO simple all I am trying to do is pass that variable to the next page!!! I think its becuse Im using an image input type instead of submit because I have NEVER had this problem before!!! Any help at all is GREATLY appreciated at this point! Thanks guys!! Are you setting the value gotten from paypal in the input field? <input type="text" style=" width:230px; height:60px; border:2px dashed #D1C7AC; font-size:18px;" name="email" value="$_POST['paypal_email']"> Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353416 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 OMG nevermind!! Topic solved. I forgot to switch the form method from "post" to "get". Thats why it didnt work! Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353417 Share on other sites More sharing options...
jdock1 Posted June 13, 2012 Author Share Posted June 13, 2012 Oh, I didnt even read the last few replies. Those are all great ways that would have probably worked as well. I made it way more complicated than it should have been! But thanks guys, I love this site you guys are awesome. Quote Link to comment https://forums.phpfreaks.com/topic/264084-is-there-anyway-i-can-use-header-location-after-the-first-few-lines-of-html/#findComment-1353418 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.