0

I do not think that I am doing this the right way, but here goes it. I want to be able to have two php pages mypage.php and mypage2.php. mypage2.php has plain text data on it (say a 8 digit number) and it is just being displayed via the echo command.

I want to know if when I am on mypage.php if I can grab that number and display it on mypage.php rather than open up mypage2.php and display it there?

So a hypothetical example of mypage.php might be:

echo "My secret number is: " . magic_command("mypage2.php");

I know that one way to do this is with $_SESSION, but doesn't that involve still navigationg to mypage2.php, storing the number in $_SESSION. Then telling it to go back to mypage.php?

4

4 回答 4

0

You can do:

include 'mypage2.php';

in mypage.php and in mypage2.php:

echo '12345678';

Easy as pie!

于 2013-04-26T18:39:34.317 回答
0

The way you're presenting your question makes me think that you're doing this the hard way. You could store the information in a variable, include the page, and echo it that way. However, I'm assuming there is more to it than that, in which case you're probably looking for a cURL, or even a file_get_contents solution. Now that I think about it, there are a few ways. Just have to do some research.

于 2013-04-26T18:40:44.187 回答
0

If fopen_wrappers are enabled, you can grab the output of one page into another with readfile(), like so:

$secret = readfile('http://server/blah/mypage2.php');
echo "My secret number is: $secret";   
于 2013-04-26T18:43:25.237 回答
0

If that number is user-specific, you should probably store it in a database and then call it when needed.

Otherwise, if you absolutely want to store it in a separate php file, use include as yvesonline suggested. include acts as if the script in mypage2.php is now inserted into mypage.php.

于 2013-04-26T18:54:51.693 回答