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;

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.