1

I am having issues with the code to access a remote website server2 from another website server1. The code I use from inside the server2 to log in is the following code:

require_once("http://server2.com/access/models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}

//Prevent the user visiting the logged in page if he/she is already logged in
if(isUserLoggedIn()) { header("Location: http://server2.com/access/account.php"); die(); }

On server2 it looks like I can not use require_once() because the page does not pass and when I use include() then prevent the user visiting does not pass. I think I am missing a code like cURL or path. Can anybody post the code to call my server2 from a another remote server1?

4

1 回答 1

2

You can't include/require PHP pages from another server because those php-files are getting parsed. You will end up getting the parsed HTML code or non at all if your config.php meets minimum safety standards. You'd have to open it differently but be aware that if you can open config.php in an easy way remotely, everyone else can too...

I suggest not to use include at all but try a different approach: for example via a php script on that second server that returns you plain text like:

login|logout
ok|error
id_Paul23
pwHash_asdf02302afbd33

the second items after the | represent an alternative response if you have an erroneus login attempt. Your user sends the login-data to your script on server 1 which attempts a login-try on that special script on server 2 which returns the result above and you can then do whatever you want on server 1.

Or better: send/receive the data in a standardized format like JSON. You already have functions in PHP for that: json_encode() and json_decode() to parse your data.

于 2013-07-28T19:47:07.273 回答