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?

3
  • stackoverflow.com/questions/5675550/… Commented Nov 14, 2015 at 9: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? Commented Nov 14, 2015 at 9: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? Commented Nov 14, 2015 at 9:54

1 Answer 1

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.

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

Comments

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.