Jump to content

Is there ANYWAY I can use header location AFTER the first few lines of HTML?!?


jdock1

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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']

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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']">

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.