?
Solved

php header function probs

Posted on 2003-02-27
13
Medium Priority
?
259 Views
Last Modified: 2011-04-14
<?php
$mailadres="anyoldemail.com";
$subject="";
$from ="From: \"DOMAIN.COM\" <support@DOMAIN.com> ";
$body="";
mail($mailadres,$subject,$body,$from);
header( "Location: http://www.where_you_want_to_go.com/" );
exit;
?>

Hi, im using the above code to forward to 2checkout.com for order processing, a form of variables is taken before this page, and the variables work fine, the email is sent correctly etc, but once the header bit executes to the 2checkout site the variables are no longer existed, I know they work fine as I set the form to send directly to 2checkout and it works, I can also get the above to email me form contents, but for some reason they are gone once the header is executed, any ideas ?

Regards
0
Comment
Question by:MirageSF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
13 Comments
 
LVL 6

Expert Comment

by:carchitect
ID: 8040151
try using javascript
write this after php code

<SCRIPT LANGUAGE="JavaScript">
<!--
self.location.href="filename.php";
//-->
</SCRIPT>
0
 
LVL 1

Expert Comment

by:Jonza
ID: 8040182
you have headers allready set somewhere.
is that the only script in the file?
then the only possibility is to use javascript:
i'd do it like this:
 
<?php
$mailadres="anyoldemail.com";
$subject="";
$from ="From: \"DOMAIN.COM\" <support@DOMAIN.com> ";
$body="";
mail($mailadres,$subject,$body,$from);
print("<script type='text/javascript'>window.location='http://whatever.com';</script>");
exit;
?>
0
 
LVL 1

Expert Comment

by:Jonza
ID: 8040185
no wait..
you don't need that exit;
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 15

Expert Comment

by:VGR
ID: 8040266
yes, true for the exit; but it's definitely cleaner.
The problem may come from the absence of session_start(); at the beginning of the PHP script ;-)

Anyway, the browser's window where this script executes will indeed "lose" the variable contents, but you should not care as it is a redirection. The remote server doesn't session_start() or share data with you :D :D

If this can be of any help, I suggest writing a javascript snippet (easy) that opens a new window, sends to data via redirection [spawning an other window), and closes itself.

Anyway, you can't expect a redirected window to still hold YOUR server's values. So you have to make the redirection harmless to YOUR work flow
0
 

Author Comment

by:MirageSF
ID: 8040568
I need it to pass the variables because I take the data via my form and pass it to 2checout.com who takes credit card details etc, but includes data i sent it, but inbetween all this I need it to send me an email once submit is clicked before it forwards to 2checkout
0
 
LVL 6

Expert Comment

by:carchitect
ID: 8040606
hey javascript is not a bad option to send your variables...
another option is to include your file with include function..

like

<?
mail code

include 'filename.php';
exit;
?>

regards
0
 

Author Comment

by:MirageSF
ID: 8040704
Ok, another way ive thought instead of passing the form to another page to send the email, then onto the payment system... this routine checks the form to make sure its completed, the php code below it needs to be inserted into this java so that if all is valid the php code is executed, if this is possible !

The idea is if the form is valid to send me an email to confirm details, it then automatically goes to the next site for credit card etc, idea of using php is to hide this email stuff from the browser

<script language="JavaScript" type="text/javascript">
function check_form ()
{
  valid = true; // assume valid
  if (document.form1.fullname.value.length == 0)
        { valid = false; alert('Full Name Required');
        document.form1.fullname.focus(); return false; }

  if (document.form1.email.value.length == 0)
        { valid = false; alert('Contact Email Required');
        document.form1.email.focus(); return false; }

  if (document.form1.street_address.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.street_address.focus(); return false; }

  if (document.form1.city.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.city.focus(); return false; }

  if (document.form1.state.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.state.focus(); return false; }

  if (document.form1.zip.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.zip.focus(); return false; }

  if (document.form1.country.value.length == 0)
        { valid = false; alert('Full Address Required');
        document.form1.country.focus(); return false; }

  if (document.form1.domain.value.length == 0)
        { valid = false; alert('Domain Name Required');
        document.form1.domain.focus(); return false; }


  if (document.form1.checkbox.checked == false )
        { valid = false; alert('You must agree to terms & conditions!');
        document.form1.checkbox.focus();return false; }
}
</script>


>>> PHP

<?php
$mailadres="sales@xcensus.com";
$from ="From: \"$email\" <$email> ";
$subject = "HOSTING PLAN ORDER: XS-PREMIUM";
$body="
HOSTING PLAN ORDER: XS-PREMIUM

CLIENTS NAME: $fullname

CONTACT EMAIL: $email

DOMAIN: $domain

CLIENTS ADDRESS: $street_address, $city, $state, $zip, $country
";
mail($mailadres,$subject,$body,$from);
?>


0
 

Expert Comment

by:baeuml
ID: 8051911
Are you looking for something like

header ("Location: http://www.somedomain.com?var1=content&var2=content");

??

0
 
LVL 1

Expert Comment

by:Steves2001
ID: 8058981
Does the page expect only post form information or will it accept get if so just append your data to the url using standard get syntax (might have to urlencode).

Just a suggestion
0
 

Author Comment

by:MirageSF
ID: 8059343
No, I just need to execute that code somewhere within that java code, so if all is TRUE then execute that bit of PHP not sure on correct syntax to do that tho
0
 
LVL 1

Accepted Solution

by:
Steves2001 earned 200 total points
ID: 8070257
It looks like you are going to have to recreate all of the headers, when you send the location header to the new url no post information is sent (the browser builds this information when you submit the form) if you cannot build the information as part of the url i.e. in the same way as using the get method when constructing your html form you have two options

option one
Construct a page with an identical form as the previous page using PHP to set the values of the fields and use JavaScript to auto post it using the JavaScript submit() function.

option two
You can in PHP build all of the post information with code before you send the location header a good reference on how to do this can be found here

http://www.faqts.com/knowledge_base/view.phtml/aid/12039/fid/51

as you can see it's not that simple but has the advantage of being server side so document object model problems with different browsers.

Another possible option is to do it all with JavaScript storing form data in a separate frame and checking submitting the information twice once to your mail script, once to the url.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question