开发者

Using readfile() with remote URL and SSL

开发者 https://www.devze.com 2023-01-02 17:04 出处:网络
I have a php-based website that uses SSL and requires a a user to login before accessing any page. I would like to allow access to this site from another domain, so that the functionality remains the

I have a php-based website that uses SSL and requires a a user to login before accessing any page. I would like to allow access to this site from another domain, so that the functionality remains the same, but the look, feel and domain changes for the user (with the added advantage that I have to maintain only one version of the code).

Having do开发者_StackOverflow中文版ne some reading, I'm using readfile() function calls in php files on the secondary server to corresponding files on the primary server. For example, the login.php on the primary server is accessed from the secondary server by a file called login.php containing readfile("http://www.primarydomain.com/login.php") (and nothing else).

Now the problem - I can't even login! The login page appears fine when called initially, but when login user and pwd are entered and submitted, it's as if the remote server doesn't see the $_SERVER['REQUEST_METHOD'] variable that triggers form processing and just loads as an empty form.

Any ideas what I'm doing wrong or what configuation I might need to change?

Thanks!


Creating a single PHP file and then using it for the same purpose across multiple sites is a great idea. However, the ways in which that file can be used in this manner depend on the general infrastructure of your hosting package.

If you have a single hosting account, which allows for the hosting of all of the affected sites under the one account, you should be able to call the common file (in this case login.php) using the include() or require() functions.

<?php
require( '/home/1234/public_html/common/login.php' );
?>

In which case, all of the functionality of that PHP file will be executed as if it were a part of the calling page.

If you have multiple sites across multiple hosting accounts/servers, the above is no longer possible. Using a readfile() function would be able to gather the output which would be seen if the URL was accessed through a browser, but the underlying functionality will be lost - ie you could not call the login.php file and have it actually perform a login on the secondary site.

In that instance, you would really need to take a copy of the actual PHP files and place them on the secondary server/account to use them.

That may make it slightly harder to manage the versions of the files, but, that is a common way to handle this issue and it does work well so long as you remember to push any file updates to all affected sites.

0

精彩评论

暂无评论...
验证码 换一张
取 消