homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
redirect to home page
Header error message
Adam5000




msg:4219472
 9:14 pm on Oct 20, 2010 (gmt 0)

Greetings

I'm trying to interface with authorize.net and I've got it all done except for the last part.

I've successfully created a test purchase and received confirmation that it went through, and now I want to send the user the home page of my site using PHP.

But when I put in the code header("location: test_home.htm"); I get the error message that apparently a lot of other people get "Header already sent, cannot be modified."

I've tried inserting the code almost everywhere I can (every way but sideways) but no luck.

Below is the abridged version of the code I'm using

Help!

<html>
<head>

<title>Subject sign up form</title>

</head>


<body>

<form action="060_signup_form.php" method="post">

<table>
<tr>

<td>
<p>
<input type="hidden" name="check" value="1">
</p>
</td>

<td>
<p>
<input type="text" name="card_number">
</p>
</td>

</tr>
<tr>

<td>
<p>
<?php

if ($_POST["check"] != "1")
{}//do nothing

else
{

$post_url = "authorize URL";

$post_values = array ("x_card_num" => "$_POST[card_number]");


$post_string = "";

foreach( $post_values as $key => $value )

{
$post_string .= "$key=" . urlencode( $value ) . "&";
}


$post_string = rtrim( $post_string, "& " );

$request = curl_init($post_url);
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
$post_response = curl_exec($request);


curl_close ($request);


$response_array = explode($post_values["x_delim_char"],$post_response);




// ****************************************************************************



// response array 3 is where the error messages are placed.
// They include "Incorrect credit card number." and "Incorrect expiration date."
// If there are no errors then the message in response array 3 reads "This transaction has been approved."

if($response_array[3]=="This transaction has been approved.")
{
header("location: test_home.htm");
}


// ****************************************************************************



echo
$response_array[3];

}


?>
</p>
</td>

</tr>
</table>

</form>

</body>
</html>

 

Matthew1980




msg:4219485
 9:44 pm on Oct 20, 2010 (gmt 0)

Hi there Adam5000,

It may not do it, but good practice dictates you would do something like this:

if($response_array[3]=="This transaction has been approved."){
header("location: test_home.htm");
//now kill the script, nothing else to execute now ;)
exit;
}

Does that make sense?

Cheers,
MRb

NomikOS




msg:4219506
 10:37 pm on Oct 20, 2010 (gmt 0)

Adam5000 you cannot use header after write html code.
Make the calculations first:

<?php
if ($_POST["check"] != "1")
{}//do nothing
... etc ...
if($response_array[3]=="This transaction has been approved.")
{
header("location: test_home.htm");
}
... etc ...
?>


then, in the same file you can add html (and php) output:

<html>
<head>
<title>Subject sign up form</title>
</head>
<body>
... etc ...
<?php echo $response_array[3];?>
... etc ...
</html>

rocknbil




msg:4220386
 3:04 pm on Oct 22, 2010 (gmt 0)

Right, the simple explanation, once you begin outputting a page, it's output, and there is already a content-type header being sent.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved