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? Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/ 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; Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663375 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']) Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663418 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); Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663467 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? Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663480 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']; Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663488 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. >_> Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663494 Share on other sites More sharing options...
lindm Posted October 12, 2008 Author Share Posted October 12, 2008 Alright. Thanks for all help! Link to comment https://forums.phpfreaks.com/topic/128098-solved-pass-php-variable-to-another-server/#findComment-663510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.