Jump to content

Calling a second PHP form as a subroutine.........possible?!


Recommended Posts

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.........thanks

JEFFERY1493



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