Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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.'');
share|improve this question
    
did you try this: include ('simplepush.php?token = '.$op); what result you get? – kakajan Sep 25 '15 at 17:43
    
When I use that the code in my other php file does not get executed. – MSU_Bulldog Sep 25 '15 at 17:45
    
check this link and this one – kakajan Sep 25 '15 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. – MSU_Bulldog Sep 25 '15 at 17:51
    
can you share simplepush.php? maybe your php code is not working – kakajan Sep 25 '15 at 17:55
up vote 1 down vote accepted

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.

share|improve this answer
    
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'])); – MSU_Bulldog Sep 25 '15 at 18:35
    
There is no need to use parameters and try and use $_REQUEST etc. See edit... – AbraCadaver Sep 25 '15 at 18:39
    
I beginning to think I need to delete this :-( – AbraCadaver Sep 25 '15 at 18:40
    
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); – MSU_Bulldog Sep 25 '15 at 19:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.