Jump to content

[SOLVED] Pass php variable to another server


lindm

Recommended Posts

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;

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?

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'];

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. >_>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.