lindm Posted October 12, 2008 Share Posted October 12, 2008 I have php scripting on two web servers: On server 1 I have a php script that generates html code, stored in a variable. I want to pass this variable to another php script found on server 2. What is the best way to do this? Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 12, 2008 Share Posted October 12, 2008 Hmm, you can't pass variables like that. Simply have a script on server 2 that calls a page on server 1 which outputs the variable content. Server 2 script $outputFromServer1 = file_get_contents('http://www.server1.com/outputforserver2.php'); Script on server 1 $outputForServer2 = "Hello World!"; echo $outputForServer2; Quote Link to comment Share on other sites More sharing options...
lindm Posted October 12, 2008 Author Share Posted October 12, 2008 Alright. What if the script on server 1 is protected by a userid and password? (Stored in $_SESSION['username'] and $_SESSION['password']) Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 12, 2008 Share Posted October 12, 2008 Then pass that info when calling the script $url = 'http://www.server1.com/outputforserver2.php?u=userid&p=password'; $outputFromServer1 = file_get_contents($url); Quote Link to comment Share on other sites More sharing options...
lindm Posted October 12, 2008 Author Share Posted October 12, 2008 Having some problems. The script1 has this part to verify if the login is ok: session_start(); if(!isset($_SESSION['username'])){ echo 'No access'; exit(); } As far as I can tell the file_get_contents() doesn't take into account SESSIONS. Is this correct? Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 12, 2008 Share Posted October 12, 2008 Correct. You will need to change the script to also accept $_GET credentials. Something along these lines: session_start(); if( !isset($_SESSION['username']) && !isset($_GET['username']) ) { echo 'No access'; exit(); } $username = (isset($_SESSION['username']))?$_SESSION['username']:$_GET['username']; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 12, 2008 Share Posted October 12, 2008 Correct. You will need to change the script to also accept $_GET credentials. Something along these lines: session_start(); if( !isset($_SESSION['username']) && !isset($_GET['username']) ) { echo 'No access'; exit(); } $username = (isset($_SESSION['username']))?$_SESSION['username']:$_GET['username']; That's really not too safe. >_> Quote Link to comment Share on other sites More sharing options...
lindm Posted October 12, 2008 Author Share Posted October 12, 2008 Alright. Thanks for all help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.