2

Details: I have a php file that runs some sql and retrieve a list of information. I run through a loop of that information and want to call another php page and pass it some parameters from the data I am looping through.

Question: How do I execute another php page from within my php?

What I Have Tried: This is the php code that should be calling the second php page (the while loop should be calling the simplepush.php page for each result I get):

<?php
require_once "../database/config.php";
header("Content-type: application/json");
$sql = "SELECT user_ip_address FROM ft_users";
$res = mssql_query($sql);
if (mssql_num_rows($res)) {

    while ($op = mssql_fetch_assoc($res)) {
        exec('simplepush.php?token = ' . $op . '');
        $arr[] = $op;
    }

    echo json_encode($arr);

    //$op = mssql_fetch_assoc($res);
    //$op['response'] = 200;
} else {
    http_response_code(420);
    $op = array(
        'response' => 420
    );
    echo json_encode($op);
}

mssql_close();
?>

I have tried the following:

include ('simplepush.php?token = '.$op.'');
exec ('simplepush.php?token = '.$op.'');
require ('simplepush.php?token = '.$op.'');
shell_exec ('simplepush.php?token = '.$op.'');
6
  • did you try this: include ('simplepush.php?token = '.$op); what result you get? Commented Sep 25, 2015 at 17:43
  • When I use that the code in my other php file does not get executed. Commented Sep 25, 2015 at 17:45
  • check this link and this one Commented Sep 25, 2015 at 17:46
  • I've actually already seen those links and none of those options are working. You can see where I put I have tried the following: it shows all of those options except for the shell_exec one and it does not work. Commented Sep 25, 2015 at 17:51
  • can you share simplepush.php? maybe your php code is not working Commented Sep 25, 2015 at 17:55

1 Answer 1

2

Just do:

include ('simplepush.php');

Now $op will be available in simplepush.php. Consider this example:

//index.php
while ($op = mssql_fetch_assoc($res)) {
    include ('simplepush.php');
    $arr[] = $op;
}

//simplepush.php
print_r($op);

The contents of $op will be output each time through the loop.

Sign up to request clarification or add additional context in comments.

3 Comments

Great, it is now calling my other php file. How do I get $op in my other php file, though. I do not understand what you mean by renaming $token. This is how I declare $token..... $deviceToken = trim(strip_tags($_REQUEST['token']));
I beginning to think I need to delete this :-(
I don't think you should. This helped me get it working. I changed my include statement to what you suggested and found a solution after using the print_r($op);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.