Page 1 of 1

passing session to another server

Posted: Mon Jul 11, 2011 9:39 am
by markthien
Hi guys,

My website current is serving images on the same server and I wanna take out this load to serve bu other server. I am currently putting all the image outside root folder and use readfile method to get and display the image. As you can see below script, I will check the $_SESSION['message_owner_id'] session variable. Is it possible to propagate this session variable to another server?

Code: Select all

<?php

session_start();

if(!isset($_SESSION['message_owner_id'])){
	die('<strong>Your session has expired!</strong>');
}

$file = strtolower($_GET['f']);

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

if(endswith($file, 'jpg') || endswith($file, 'png') || endswith($file, 'gif') || endswith($file, 'tif') || endswith($file, 'tiff') || endswith($file, 'bmp')){
	header('Content-type:image');
	header('Content-Disposition: inline; filename="' . $file . '"');	
} else {
	// We'll be outputting a other format to prompt user to download
	header('Content-type: application');
	// It will be called downloaded.pdf
	header('Content-Disposition: attachment; filename="' . $file . '"');	
}

$file = '/var/upload/images/' . $_SESSION['message_owner_id'] . '_' . $file;

if(!file_exists($file)){
	echo 'Opps, file cannot be found!';
	return;	
}
// The PDF source is in original.pdf
readfile($file);

function endswith($string, $test) {
    //$strlen = strlen($string);
    $testlen = strlen($test);
    //if ($testlen > $strlen) return false;
    return substr_compare($string, $test, -$testlen) === 0;
}
?>
regards,
Mark

Re: passing session to another server

Posted: Thu Jul 14, 2011 10:45 pm
by TheMexican
As far as I know the only possible way of doing that is by sharing the folder where the sessions are stored and reading them from the other server using regular file I/O.

Re: passing session to another server

Posted: Fri Jul 15, 2011 7:42 am
by VladSun
Something like that?
viewtopic.php?f=19&t=94949

Re: passing session to another server

Posted: Mon Jul 25, 2011 1:41 pm
by Benjamin
:arrow: Moved to PHP - Code