2

Currently I'm using web matrix2 to build my php application. I was testing passing the query string to another php using GET

Scenario 1: I have index.php and test.php
in index.php: I have a php statement include("/test.php");
in test.php: i only have 2 statements echo "hi"; and echo $_GET["msg"]; when I run it, nothing appear in my browser

When I get rid of the echo $_GET["msg"];, it works again.

Scenario 2: I have index.php and test.php
in index.php: I have a php statement include("/test.php?msg=hihihi");
in test.php: i only have 2 statements echo "hi"; and echo $_GET["msg"]; when I run it, nothing appear in my browser

Even I tried to type the Url http://localhost:port/test.php?msg=hihihi, nothing appear as well..~

Then I tried to test it using a link

<a href="http://localhost:62878/menu/AddCat.php?msg=hihihi">link</a>

still nothing was displayed at AddCat.php page.

I have tried it in EasyPhp...~ The error showed in EasyPHP is
Fatal error: require(): Failed opening required 'test.php?msg=hihi' (include_path='.;C:\php\pear') in C:\Program Files\EasyPHP-12.1\www\testing\index.php on line 2
if I put the query string together with the url in the php include statement.

I'm not sure how why my code didn't work previously, but now fix.


thanks.

WenHao
  • 1,183
  • 1
  • 15
  • 46
  • 1
    My guess is that the test.php cannot be found because `/` in PHP is different from `/` in HTML. You should enable error reporting to be sure. – str Feb 02 '13 at 18:19
  • better you put all the file contents "as it is" here. – Kalpesh Feb 02 '13 at 18:33
  • At the moment you are trying to include data by making an HTTP request to a file and passing data to it in a query string. Don't. Rewrite the page as a function, then include the file containing the function, then call the function with the data you want to pass as an argument. – Quentin Feb 02 '13 at 18:52
  • @Quentin : do mind to tell me why it is not encourage to perform http request to a file while passing data along in the query string? Is it possible like passing along a security token as well? – WenHao Feb 03 '13 at 09:37
  • It's inefficient and hard to debug – Quentin Feb 03 '13 at 09:37

2 Answers2

1

Don't confuse the path that you see in the browser URI with the filepath on the server. The include() statement refers to the filesystem on the server and /test.php would be a document right at the top of the filesystem (somewhere you're very unlikely to be writing to).

Assuming test.php is in the same directory as the script you're trying to include it from you can simply use include("test.php")

If there's a runtime/syntax error then PHP will log this in the Apache error log, be sure to take a look at it.

James C
  • 14,047
  • 1
  • 34
  • 43
  • Indeed both are in the same directory. I also have tested include("test.php?msg=hihihi"); still nothing appear. I'm using web matrix 2, so how to check in web matrix 2 for the log file you mentioned? – WenHao Feb 02 '13 at 18:29
  • How are you going to include a file with arguments? include is like if you copied and pasted the content of the file where you write it, not as if you called it! – Federico J. Mar 15 '14 at 22:44
-1

Please run

index.php?msg=hihihi

it will show you result

Daniel
  • 10,864
  • 22
  • 84
  • 115
Ankit Agrawal
  • 6,034
  • 6
  • 25
  • 49