Sending and receiving variables within a single script.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Sending and receiving variables within a single script.

Post by Citizen »

Basically, I need to create a php script that does the following.

1. States a variable
2. Sends the variable to another domath.php script
3. Receives the result from the domath.php script
4. Prints the result

Is there any way to do this without requiring the user to click anything?
chadillac
Forum Newbie
Posts: 12
Joined: Tue Feb 28, 2006 3:30 pm
Location: Fort Lauderdale

Post by chadillac »

maybe I'm missing something, but can't you just have a script post back to itself.... or use an include to grab the variables work with them then output them to the user?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

There are potentially a couple ways you could do this:
  1. You could include() the domath.php script. Including a file essentially runs it. So, you could declare the variable, include domath.php and have the results stored in your script:

    Code: Select all

    //index.php
    <?PHP
    $a = 2;
    $b = 6;
    
    include('domath.php');
    
    echo $result;
    ?>
    
    //domath.php
    <?PHP
    $result = $a + $b;
    ?>
    
    //output would be: 8
  2. The other option would be to call that php script via the command line and capture the output from the file. Passing variables that way gets a little trickier though.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

My problem is that I need to state a variable and echo the variable in order for my Flash file on the page to be able to load the variable. The problem comes in that I dont have anywhere to echo the variable as it will look quite crappy.

My plan was going to be to echo the variable on a seperate page.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

this will most probably be accomplished using AJAX
Post Reply