1

I have build a service for all my events in the database. The service workes fine when called within javascript. Now i am trying to get the results on page load in php. On the Service Page (events.php) i have a switch function like this:

$switcher = isset($_REQUEST["set"]) ? $_REQUEST["set"] : "";
switch ($switcher)
{
case 'list':    
    $events = $_crs->listCourse();
    echo json_encode($events);
break;
...
default:
break;
}

In javascript i give a parameter that do the switch like this:

url: "events.php?set=all";

And in Php i am trying to get the results by running this:

$list = file_get_contents( "events.php?set=list&from=$from&to=$to&category=&limit=15");

Problem 1: When i do this i get this error: failed to open stream: No such file or directory in

Problem 2: when leaving out the get variables i get the raw php code from the events.php file!

How can i solve this prpblem?

jhon dano
  • 660
  • 6
  • 23
  • http://stackoverflow.com/questions/5675550/php-include-with-get-attributes-include-file-phpq-1 – Mujnoi Gyula Tamas Nov 14 '15 at 09:11
  • @Mujnoi Gyula Tamas: thanks for your quick responde, but i dont see how that answer can help me since my question do not concern includes? – jhon dano Nov 14 '15 at 09:44
  • It's the same principle. One work around that might work is to stream from localhost, but I don't know how this will be affected on shared host. `file_get_contents( 'http://localhost/events.php?set=list&from=$from&to=$to&category=&limit=15' )`, if not use full URL with your domain name to get response. LE: why don't you create a shared class for both of your pages? – Mujnoi Gyula Tamas Nov 14 '15 at 09:54

1 Answers1

0

have a look at the man page for (file_get_contents)[http://php.net/manual/en/function.file-get-contents.php].

You are passing "events.php?set=list&from=$from&to=$to&category=&limit=15" which it understands to be a file name. Hence the message "no such file or directory".

What I think you want is to execute the file events.php and read the result.

file_get_contents can do that too. Have another look at the manual and understand the various examples to get started.