passing session to another server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
markthien
Forum Commoner
Posts: 33
Joined: Fri Feb 13, 2009 7:50 pm

passing session to another server

Post 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
TheMexican
Forum Newbie
Posts: 1
Joined: Thu Jul 14, 2011 10:31 pm

Re: passing session to another server

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: passing session to another server

Post by VladSun »

Something like that?
viewtopic.php?f=19&t=94949
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: passing session to another server

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply