jeffery1493 Posted January 19, 2007 Share Posted January 19, 2007 Hi All,I have been struggling for this problem for quite some time.I have a payment program being called from within a PHP forum (kind of like this one) by this routine:echo"<script>location.href='paymentconfirm." .$phpEx."?secure=" . $post_id . "';</script>";All I want to do is execute it like a GOSUB, as in, nothing in the code after this line will be executed until the called program completes successfully. The problem is with PHP, the original PHP script appears to continue on simultaneously, at the same time as the next HTML page is being executed.The idea is, you pay, or your post doesn't post. I've searched through many books and hours of websites, so burn me if you must, just help! if you know.........thanksJEFFERY1493 Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/ Share on other sites More sharing options...
.josh Posted January 19, 2007 Share Posted January 19, 2007 Php is parsed on the server and then sent to the client. That's why it "continues to run." Because php is not an event based language, you are going to have to rethink your program flow here. Now, my suggestions are little more than guesses, since I have no idea what your "bigger picture" is, but you mentioned some kind of "pay-per-post" system, so my suggestion would be to setup a "bank" where the user pays ahead of time for x amount of posts and then when the user clicks the submit button to post, the handling script first checks to see if the user has enough "credits" for the post and if so, decriment "credits," insert/display. If not, don't insert, and also give an error message, or hold the post in a que and send them to a payment screen to get more credits, or something. But again, I'm just kind of feeling in the dark here, as I don't know the whole background of your situation. Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164290 Share on other sites More sharing options...
jeffery1493 Posted January 19, 2007 Author Share Posted January 19, 2007 crap! I'm ruined.Surely there must be some way to 'suspend' a program in PHP, maybe put a WHILE loop in there? Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164296 Share on other sites More sharing options...
.josh Posted January 19, 2007 Share Posted January 19, 2007 nopers. not in the way that you are wanting to do it. You can do that with javascript, but seeing as how money is involved, I don't recommend it, since people can just turn it off or alter it. I can think of some scenarios involving sessions that might help, but you're going to have to give more details on what exactly you're wanting to do here... Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164298 Share on other sites More sharing options...
kenrbnsn Posted January 19, 2007 Share Posted January 19, 2007 I would use AJAX in this case. If you're unfamiliar with AJAX, there is a forum here. You can also look at the Yahoo! User Interface Javascript libraries, particularly the [url=http://developer.yahoo.com/yui/connection/]Connection Manager[/url]Ken Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164299 Share on other sites More sharing options...
jeffery1493 Posted January 19, 2007 Author Share Posted January 19, 2007 My attempts at this bombed:(program 1)-------------------session_start();echo"<script>location.href='paymentconfirm." .$phpEx."?secure=" . $post_id . "';</script>";$_SESSION['waiting']="YES";while ( $_SESSION['waiting']="YES" ){ $x=1; // Sit and do nothing, until variable changes}<OK, Proceed with posting...>--------------------(program 2:)--------------------<Do payment routine...>$_SESSION['waiting']="NO";--------------------What I am doing is a forum, like this one, where you pay to post. You fill out the form, just like you do when you click "New Topic" here, and then after you click POST, you go to a payment routine where you are charged a fee.When the fee routine completes, if it is successful, your topic posts. If it is unsuccessful, your topic should not post. I don't know what else I can say........ Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164301 Share on other sites More sharing options...
kenrbnsn Posted January 19, 2007 Share Posted January 19, 2007 If you want to stay within PHP, take a look at the [url=http://www.php.net/manual/en/ref.curl.php]CURL[/url] routines.You might be able to do what you want with them.Ken Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164305 Share on other sites More sharing options...
jeffery1493 Posted January 19, 2007 Author Share Posted January 19, 2007 They need to add a smiley with a noose........ Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164323 Share on other sites More sharing options...
.josh Posted January 19, 2007 Share Posted January 19, 2007 [quote author=jeffery1493 link=topic=123098.msg508441#msg508441 date=1169189181]What I am doing is a forum, like this one, where you pay to post. You fill out the form, just like you do when you click "New Topic" here, and then after you click POST, you go to a payment routine where you are charged a fee.When the fee routine completes, if it is successful, your topic posts. If it is unsuccessful, your topic should not post. I don't know what else I can say........[/quote]Okay do it like this example:makepost.php[code]<?php session_start(); // form for making post // I just have a generic form with a generic text field, for example sake echo <<<POSTFORM <form action='makepayment.php' method='post'> <input type='text' name='userpost'> <input type='submit' value='post'> </form>POSTFORM;?>[/code]makepayment.php[code]<?php session_start(); if ($_POST['userpost']) { // save the userpost info in a session var $_SESSION['userpost'] = $_POST['userpost']; // form for taking payment // I just have a generic form with a generic text field, for example sake echo <<<POSTFORM <form action='processpayment.php' method='post'> <input type='text' name='ccname'> <br/> <input type='text' name='ccnumber'> <input type='submit' value='post'> </form>POSTFORM; }?>[/code]processpayment.php[code]<?php session_start(); if ($_POST['ccname'] && $_POST['ccnumber']) { // generic boolean var for illustration purposes $payment = false; // do whatever you do to process payment, using $_POST vars // set $payment to true on success if ($payment == true) { // insert/display new post with $_SESSION var // or you could make $payment a session var too and // do like header('Location: processpost.php); exit(); // and go to another script altogether if you want to seperate // the payment and the post process scripts } else { // payment didn't go through or something happened. throw out // an error or whatever. } }?>[/code]This is just a basic skeleton. You will obviously want to throw in form validation, as well as lots of other security checks. Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164561 Share on other sites More sharing options...
effigy Posted January 19, 2007 Share Posted January 19, 2007 Have you tried forking the process? Quote Link to comment https://forums.phpfreaks.com/topic/34844-calling-a-second-php-form-as-a-subroutinepossible/#findComment-164569 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.