dolcezza Posted December 5, 2007 Share Posted December 5, 2007 I have a form. When the form is submitted I want it to 1. run my php script which puts all info in database (this is done and works fine on it's own) 2.Take the user to paypal using paypla subscription/ipn (this would be gotten from paypal) form action has to be: <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> Can anybody guide me in the right direction to make 1 submit button do both? Thanks in advance. Susan Quote Link to comment Share on other sites More sharing options...
Lumio Posted December 5, 2007 Share Posted December 5, 2007 use header() for that. Quote Link to comment Share on other sites More sharing options...
dolcezza Posted December 5, 2007 Author Share Posted December 5, 2007 wouldn't header take you to a different page other than paypal payment page? Quote Link to comment Share on other sites More sharing options...
Stooney Posted December 5, 2007 Share Posted December 5, 2007 header("Location: https://www.paypal.com/cgi-bin/webscr"); Quote Link to comment Share on other sites More sharing options...
dolcezza Posted December 5, 2007 Author Share Posted December 5, 2007 then where would you put the code to the php page editing the database while still making sure paypal gets all the variables it needs? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Action takes care of that in your Form. Quote Link to comment Share on other sites More sharing options...
dolcezza Posted December 5, 2007 Author Share Posted December 5, 2007 sorry, but I am new at this. If I'm understanding correctly, you change the action from paypal stuff to the php script, and put paypal in the header(), right? The header() command goes in the php document? And this still has all the variables from the form for paypal? Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 5, 2007 Share Posted December 5, 2007 IPN is a two stage process, first off you have a page with your stuff on it (an item or a list of stuff), you send this info to paypal using a form. e.g. this use's the <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> bit... This leads your client to a set of paypal pages, once almost finished the paypal server requests your authorisation page. Here you check the stuff and communicate with paypal through a socket, then they'll send back either "VERIFIED" or "INVALID", at this point you have confirmation of sale. Be aware of the differences between the following address's: $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30); Quote Link to comment Share on other sites More sharing options...
dolcezza Posted December 5, 2007 Author Share Posted December 5, 2007 That part I understand, but I want everything posted to the database first, then directed to paypal for payment, then back to a confirmation page. How do I get it to run my insert php script before redirecting to paypal? Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 5, 2007 Share Posted December 5, 2007 Well, let's say you have a confirmation of order page, as you produce this page you may put the info to db, also on this page you have the paypal button. At this point, no payment has been made, not until they've confirmed with paypal, then paypal have confirmed with you. After that paypal return them to you. Alternatively you have a confirm button, that links to one of your php pages which records some info, then redirects (using 'header' as described above) to the paypal site, all is same after that... 1) Confirm -> Paypal -> Verify -> Paypal -> Confirm2 2) Confirm -> Confirm.php -> Verify -> Paypal -> Confirm2 Quote Link to comment Share on other sites More sharing options...
dolcezza Posted December 5, 2007 Author Share Posted December 5, 2007 so if i put header(paypalpage) in my php page, it will redirect to paypal, something like this... $query = mysql_query("INSERT INTO caregivers (firstname, lastname, email, phone, county, experience, date) VALUES ('$firstname', '$lastname', '$email', '$phone', '$county', '$experience', '$date')") or die(mysql_error()); if($query) { header(redirect to paypal page) but will it still have all the info in the form that paypal needs or do I have to redeclare all that info? (I was trying to avoid having a confirm page) Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 6, 2007 Share Posted December 6, 2007 You could connect to the paypal page with a socket (see http://uk3.php.net/function.fsockopen for https fsockopen details) and use it like you'd use telnet: POST /cgi-bin/webscr HTTP/1.0 From: a@b.com User-Agent: CrashNBurn Content-Type: application/x-www-form-urlencoded Content-Length: 555 cmd=_xclick&business=aselle_007_biz@hotmail.co.uk&item_name=Image&item_number=555amount=3.21 Adjust 'Content-Length' according to the data your passing, also change the data... If I were you i'd practice this on the sandbox or even your own setup first, i've never had to use on https... have fun! Quote Link to comment Share on other sites More sharing options...
dolcezza Posted December 6, 2007 Author Share Posted December 6, 2007 Thanks for the info, but that I think may still be a bit over my head. I guess I'll go with first option and have a confirm page before sending to paypal. Susan Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 6, 2007 Share Posted December 6, 2007 Having a play with telnet helps you understand how a protocol works, a basic one to look at is when constructing an email with php. But even simpler is getting web pages and the such. You might enjoi the following if you've not had a go before: http://www.groovyweb.uklinux.net/?page_name=Using%20http%20commands%20through%20telnet http://www.pasteur.fr/formation/infobio/web/cours/ch01.html http://www.jmarshall.com/easy/http/ But, yes the original way is simpler. Not that i've tried 'curl', but that might have some builtin stuff for this type of thing, i'm sure someone else could tell you more... Have fun! Quote Link to comment 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.