This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » How to pass session id in URL?
icon5.gif  How to pass session id in URL? [message #28723] Tue, 05 June 2007 13:13 Go to next message
alossenko  is currently offline alossenko
Messages: 3
Registered: June 2007
Junior Member
Hello,

I need to disable cookie session management for one action and pass the session_id in the url. The rest of the application should use cookies for sessions.

I want a url something like this /blabla/session/5g3g5i4g4vbu4uz

Is this possible? Confused

Thanks

Re: How to pass session id in URL? [message #28728 is a reply to message #28723 ] Tue, 05 June 2007 13:48 Go to previous messageGo to next message
pezetgee
Messages: 734
Registered: March 2006
Faithful Member
It's possible.
See http://www.symfony-project.com/book/trunk/06-Inside-the-Cont roller-Layer#Session%20Management
Re: How to pass session id in URL? [message #28733 is a reply to message #28723 ] Tue, 05 June 2007 14:02 Go to previous messageGo to next message
alossenko  is currently offline alossenko
Messages: 3
Registered: June 2007
Junior Member
Thanks

But will setting session.use_trans_sid = 1 in php.ini disable client-side session cookie management for the whole application? I need it for one action only. The rest of the application must use cookies.

Are there any alternatives to this, without messing with php.ini ?
Re: How to pass session id in URL? [message #28735 is a reply to message #28733 ] Tue, 05 June 2007 14:13 Go to previous messageGo to next message
pezetgee
Messages: 734
Registered: March 2006
Faithful Member
ahh..
didn't read the post correctly..

yes 'session.use_trans_sid = 1' will disable it for the whole app.

I'm not sure if you can do it on module level..
Re: How to pass session id in URL? [message #28756 is a reply to message #28735 ] Tue, 05 June 2007 17:39 Go to previous messageGo to next message
cblin  is currently offline cblin
Messages: 265
Registered: July 2006
Faithful Member
I'd like to know why do you need to pass the session id in the url ?
Note that the cookie will always be sent by the browser (so I do not see the point to add the session id in the url)

if you need to get the session id in your action, then a call to session_id() will give it to you (maybe there is a symfony function to do this but I do not know it).

otherwise, you can always do the following (to be adapted to your case) :
<form action="/blabla">
  <input type="hidden" name="session" id="session" />
  <input type="submit" />
</form>

<script>
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
$('session').value = readCookie('symfony');
</script>



Re: How to pass session id in URL? [message #28758 is a reply to message #28723 ] Tue, 05 June 2007 17:56 Go to previous messageGo to next message
alossenko  is currently offline alossenko
Messages: 3
Registered: June 2007
Junior Member
I am trying to integrate SWFupload (http://swfupload.mammon.se/) into symfony.

Thе Flash script, that is being used for uploading, is sending cookies from Internet Explorer, even when I am in Firefox. It is very weird.

If you are logged in only in Firefox and upload a file, the Security Filter thinks that you are not logged in (because he got the cookies from IE) and the upload fails. So I wanted to try and pass the session_id as url parameter.


Sad story Smile I've integrated a Java Applet now for uploading. I don't like applets, but it seems that it is the only solution for multiple file upload.

[Updated on: Tue, 05 June 2007 17:58]

Re: How to pass session id in URL? [message #33546 is a reply to message #28758 ] Fri, 17 August 2007 03:28 Go to previous messageGo to next message
infect  is currently offline infect
Messages: 98
Registered: January 2006
Member
I came across the same issue while trying to integrate the swfuploader. This worked:

	window.onload = function() {
		// Max settings
		swfu = new SWFUpload({
			upload_script : "<?php echo url_for('file/upload') ?>?<?php echo ini_get('session.name') ?>=<?php echo session_id() ?>",
			target : "SWFUploadTarget",
			flash_path : "/swf/SWFUpload.swf",
			allowed_filesize : 30720,	// 30 MB
			browse_link_class : "swfuploadbtn browsebtn",
			upload_link_class : "swfuploadbtn uploadbtn",
			flash_loaded_callback : 'swfu.flashLoaded',
			upload_file_queued_callback : "fileQueued",
			upload_file_start_callback : 'uploadFileStart',
			upload_progress_callback : 'uploadProgress',
			upload_file_complete_callback : 'uploadFileComplete',
			upload_file_cancel_callback : 'uploadFileCancelled',
			upload_queue_complete_callback : 'uploadQueueComplete',
			upload_error_callback : 'uploadError',
			upload_cancel_callback : 'uploadCancel',
			auto_upload : false
		});



The key thing to note is that the session id must be appended to the symfony url with a question mark, so you can't include it in the url that you pass to functions like "url_for" as symfony will strip out the question mark in favor of the /key/value url syntax.

So, you'll notice in the code above, that I used this:

<?php echo url_for('file/upload'?>?<?php echo ini_get('session.name'?>=<?php echo session_id() ?>

... which seems to work and will successfully re-attach the session. I, too, was having the issue where symfony would redirect to the login page since the session wasn't being correctly attached. I hope this helps.


Mark Quezada
MirthLab
Re: How to pass session id in URL? [message #33548 is a reply to message #33546 ] Fri, 17 August 2007 06:14 Go to previous messageGo to next message
mickb  is currently offline mickb
Messages: 2
Registered: March 2007
Location: Discovery Bay, CA
Junior Member
thank you sooooo much!

I can go sleep now Smile
Re: How to pass session id in URL? [message #37469 is a reply to message #33548 ] Mon, 15 October 2007 19:24 Go to previous messageGo to next message
seb.b  is currently offline seb.b
Messages: 37
Registered: July 2006
Member
Hello,
I have got the same problem with SWFUpload.
I lost my session under Firefox, not under IE.
I try the code you give
<?php echo url_for('file/upload') ?>?<?php echo ini_get('session.name') ?>=<?php echo session_id() ?> 


But I've always no session.

Is there another things to do?

Thx!
Re: How to pass session id in URL? [message #37480 is a reply to message #37469 ] Mon, 15 October 2007 23:15 Go to previous messageGo to next message
mickb  is currently offline mickb
Messages: 2
Registered: March 2007
Location: Discovery Bay, CA
Junior Member
the only thing I could think of if it works in IE but not in Firefox is that you may be using EMBED and OBJECT tags and that you have valid url set for OBJECT but not for EMBED tag. I would go to view->page source in Firefox and check to make sure that your url renders with session information...

[Updated on: Mon, 15 October 2007 23:16]

Re: How to pass session id in URL? [message #37481 is a reply to message #37480 ] Mon, 15 October 2007 23:22 Go to previous messageGo to next message
seb.b  is currently offline seb.b
Messages: 37
Registered: July 2006
Member
I've got :
upload_url: " /backcom_dev.php/upload/fileupload?symfony=9b8713aed2af20f43 4ecf41bd159ef31 "

It seems to be ok... Any ideas?
Re: How to pass session id in URL? [message #39149 is a reply to message #28723 ] Fri, 09 November 2007 12:53 Go to previous messageGo to next message
userfriendly  is currently offline userfriendly
Messages: 20
Registered: August 2007
Location: Aachen, Germany
Junior Member
i have a similar problem, trying to get flash remoting working with my symfony php sessions.

i don't quite know how to initialize the correct session during execution of the remoting class method, because a new session is already initialized at that point.

i know i could derive my own session class, say mySessionStorage extends sfSessionStorage, but then i don't know how to access the amf request parameters sent by the flash client, because the remoting class isn't instantiated at that point.

meh. Confused
Re: How to pass session id in URL? [message #41229 is a reply to message #39149 ] Sun, 09 December 2007 11:28 Go to previous messageGo to next message
zazabe  is currently offline zazabe
Messages: 2
Registered: December 2007
Location: Paris
Junior Member
Hello,

The swfuploader 2.0 is out, now you can easily past parameters to the action class.

I use sfGuard and the remember key is very usefull to make swfupload work with symfony session.
If you use sfGuard, see in sfGuardBasicSecurityFilter.class.php what you can do.

[Updated on: Sun, 09 December 2007 11:33]

Re: How to pass session id in URL? [message #42994 is a reply to message #28723 ] Tue, 08 January 2008 08:55 Go to previous messageGo to next message
yura  is currently offline yura
Messages: 17
Registered: November 2007
Location: Russia
Junior Member
Had the same problem with flash under firefox sending session id cookie from IE. I think I'll do special auth just for upload action. But there is another problem - is there any way to stop swfupload from sending any cookies at all?
Re: How to pass session id in URL? [message #42999 is a reply to message #42994 ] Tue, 08 January 2008 09:47 Go to previous messageGo to next message
infect  is currently offline infect
Messages: 98
Registered: January 2006
Member
yura,

I'm not quite sure what you mean about stopping swfupload from "sending" cookies... as far as I know, swfupload doesn't *send* cookies at all...


Mark Quezada
MirthLab
Re: How to pass session id in URL? [message #43002 is a reply to message #28723 ] Tue, 08 January 2008 10:02 Go to previous messageGo to next message
yura  is currently offline yura
Messages: 17
Registered: November 2007
Location: Russia
Junior Member
infect, well it does Smile

in the upload action I do:

$this->getContext()->getLogger()->info('COOKIE ' . print_r($_COOKIE, true));


and it ends up with something like this in a log file:

Jan 08 11:10:27 symfony [info] COOKIE Array
(
    [session_id] => tf5cekqp9iqvah2iede84f4803
)


Note, that this session_id cookie (renamed symfony cookie) is from IE, while request was initiated from Firefox browser.
Re: How to pass session id in URL? [message #43010 is a reply to message #43002 ] Tue, 08 January 2008 10:41 Go to previous messageGo to next message
userfriendly  is currently offline userfriendly
Messages: 20
Registered: August 2007
Location: Aachen, Germany
Junior Member
yura wrote on Tue, 08 January 2008 10:02


Note, that this session_id cookie (renamed symfony cookie) is from IE, while request was initiated from Firefox browser.

that's really strange. flash is starting to creep me out... Confused

what do you guys think would be sent in such a case when there's no IE installed (e.g. a linux machine)?
Re: How to pass session id in URL? [message #43011 is a reply to message #43010 ] Tue, 08 January 2008 10:43 Go to previous messageGo to next message
infect  is currently offline infect
Messages: 98
Registered: January 2006
Member
I have a feeling this may be more of an IE issue than Flash. I've never heard of this before.


Mark Quezada
MirthLab
Re: How to pass session id in URL? [message #43019 is a reply to message #28723 ] Tue, 08 January 2008 12:33 Go to previous messageGo to next message
yura  is currently offline yura
Messages: 17
Registered: November 2007
Location: Russia
Junior Member
Found in the swfupload doc

Quote:

Cookie issue

On Windows the Non-IE Flash Player plugin (FireFox, Opera, Safari, etc) sends the IE cookes regardless of the browser used. This breaks authentication and sessions for many server-side scripting technologies.


Sad
Re: How to pass session id in URL? [message #44454 is a reply to message #28723 ] Wed, 30 January 2008 15:18 Go to previous messageGo to next message
Joohn  is currently offline Joohn
Messages: 10
Registered: January 2008
Junior Member
My solution for this problem Smile

This is overriden session storage class:
class MySessionStorage extends sfSessionStorage
{
  public function initialize($context, $parameters = null)
  {
    //Shitty work-around for swfuploader
    if( $context->getActionName() == "upload")
    { 
      $sessionName = $parameters["session_name"];

      if($value = $context->getRequest()->getParameter($sessionName))
      {
        session_name($sessionName);
        session_id($value);
      } 
    }
    
    parent::initialize($context, $parameters);
  }
}


It must be configured in application's factory.yml file:
storage:
  class: MySessionStorage
  param:
    session_name: my_session


And a modification to swf upload initializer which already was posted here:

 
swfu = new SWFUpload
({ 
   upload_url : "<?php echo url_for("fileinfo/upload"); ?>?<?php echo ini_get('session.name') ?>=<?php echo session_id() ?>", 
...


Works great for me in Firefox and IE7
Cheers Smile
Re: How to pass session id in URL? [message #44908 is a reply to message #28723 ] Wed, 06 February 2008 11:22 Go to previous messageGo to next message
angelo  is currently offline angelo
Messages: 1
Registered: February 2008
Junior Member
Hello,

I'm begnier in symfony and i don't understand very weel how to integrate swfupload in symfony.

Does anyone has got the code to put swf in symfony?

Best regards

Angelo
Re: How to pass session id in URL? [message #50564 is a reply to message #44908 ] Tue, 22 April 2008 10:25 Go to previous messageGo to next message
lbertin  is currently offline lbertin
Messages: 22
Registered: March 2008
Location: France
Junior Member
Anyone here who used SWFUpload with Symfony would care to share their code ?

Thanks


Laurent
Re: How to pass session id in URL? [message #52255 is a reply to message #44454 ] Sun, 18 May 2008 23:08 Go to previous messageGo to next message
manu  is currently offline manu
Messages: 2
Registered: May 2008
Junior Member
You rock! This is awesome!!

Just a coincidence that I tried Google before spending three hours developing a solution myself... Thank you!!

Manu
Re: How to pass session id in URL? [message #53385 is a reply to message #33546 ] Tue, 03 June 2008 18:48 Go to previous messageGo to next message
mysyfy  is currently offline mysyfy
Messages: 25
Registered: June 2006
Location: Londrina
Junior Member
Brilliant! Smile

Worked fine!.

Cheers

Lucas
Re: How to pass session id in URL? [message #56671 is a reply to message #28723 ] Tue, 22 July 2008 09:34 Go to previous messageGo to next message
adriani  is currently offline adriani
Messages: 7
Registered: July 2008
Location: Iasi
Junior Member
Hi,

does anyone have a clue how to set a specific application, from the symfony project, to include automatically the session id and the session name in the url ?

Thanks
Re: How to pass session id in URL? [message #70295 is a reply to message #44454 ] Tue, 20 January 2009 12:14 Go to previous messageGo to next message
osoria  is currently offline osoria
Messages: 7
Registered: October 2007
Location: Barcelona
Junior Member
Joohn wrote on Wed, 30 January 2008 15:18

My solution for this problem Smile

This is overriden session storage class:
class MySessionStorage extends sfSessionStorage
{
  public function initialize($context, $parameters = null)
  {
    //Shitty work-around for swfuploader
    if( $context->getActionName() == "upload")
    { 
      $sessionName = $parameters["session_name"];

      if($value = $context->getRequest()->getParameter($sessionName))
      {
        session_name($sessionName);
        session_id($value);
      } 
    }
    
    parent::initialize($context, $parameters);
  }
}


It must be configured in application's factory.yml file:
storage:
  class: MySessionStorage
  param:
    session_name: my_session


And a modification to swf upload initializer which already was posted here:

 
swfu = new SWFUpload
({ 
   upload_url : "<?php echo url_for("fileinfo/upload"); ?>?<?php echo ini_get('session.name') ?>=<?php echo session_id() ?>", 
...


Works great for me in Firefox and IE7
Cheers Smile


I don't understand! I have tried this one and in MySessionStorage class I don't have any session. That is when I do $context->getActionName() it returns nothing.

Crying or Very Sad
Re: How to pass session id in URL? [message #93381 is a reply to message #70295 ] Fri, 12 February 2010 00:18 Go to previous messageGo to next message
josecarlossm  is currently offline josecarlossm
Messages: 1
Registered: February 2010
Junior Member
Try sfContext::getInstance() instead of $context->getRequest()
Re: How to pass session id in URL? [message #99527 is a reply to message #28723 ] Fri, 21 May 2010 13:03 Go to previous messageGo to next message
WayFarer  is currently offline WayFarer
Messages: 1
Registered: May 2010
Junior Member
For symfony 1.3/1.4 it works this way:
class MySessionStorage extends sfSessionStorage
{
  public function initialize($options = null)
  {
    // work-around for swfuploader
    if(sfContext::getInstance()->getRequest()->getParameter('z')) {
      session_id(sfContext::getInstance()->getRequest()->getParameter('z'));
    }

    parent::initialize($options);
  }
}

where session_id is passed in parameter "z" from clientside,
i.e.

swfu = new SWFUpload
({ 
   upload_url : "<?php echo url_for("fileinfo/upload"); ?>?z=<?php echo session_id() ?>", 
Re: How to pass session id in URL? [message #100861 is a reply to message #28723 ] Sun, 13 June 2010 19:58 Go to previous messageGo to next message
tatom2000  is currently offline tatom2000
Messages: 14
Registered: July 2008
Junior Member
For those who run swfupload+Symfony+sfGuard , I've a problem in running all of them together.
I do the same like this link : http://www.lexik.fr/blog/symfony/symfony/gestion-dune-galeri e-photo-avec-swfupload-dans-ladmin-918

I think the problem is with sfGuard???
Any guide in "remember me" feature in sfGuard (if it'll help)????

I need to fix this urgent!!!
Thanks.
Re: How to pass session id in URL? [message #101048 is a reply to message #28723 ] Wed, 16 June 2010 14:08 Go to previous messageGo to next message
niVin  is currently offline niVin
Messages: 7
Registered: April 2010
Junior Member
Hi tatom2000,

I guess I'm having similar problems with a project Im currently working on. I also try to implement sfwupload into my admin application (with the help of sfSWFUpload plugin). I also have sfguard installed.

For my admin interface I use the javascript Mootools lib with the Mootabs plugin for a tabbed interface (content of each tab is loaded with ajax in an iframe).

My specs:
sf 1.0.17
sfGuardPlugin 1.1.13-stable
sfSWFUpload 1.0.3
mootools 1.2.4
mootabs 1.2 (which I modified for compatibility with mootools 1.2.4)

I added a sample log in the attachment..

Maybe we can help eachother out to fix this problem!

[Updated on: Wed, 16 June 2010 14:08]

icon9.gif  Re: How to pass session id in URL? [message #101395 is a reply to message #28723 ] Tue, 22 June 2010 10:20 Go to previous messageGo to next message
tatom2000  is currently offline tatom2000
Messages: 14
Registered: July 2008
Junior Member
niVin, you're using an old version of swfUpload ,but this isn't the problem.
I believe that the problem is sfGuard doesn't pass the session that passed from flash (swfUpload)
someone here in this topic talked about "remember key" in sfGuard ,and this is a thing I know nothing about.
Anybody here give a push please.
Re: How to pass session id in URL? [message #101446 is a reply to message #101395 ] Tue, 22 June 2010 19:40 Go to previous messageGo to next message
niVin  is currently offline niVin
Messages: 7
Registered: April 2010
Junior Member
hi tatom,

I gave up the struckle with swfupload and Im now using fancyupload, wich I actually get pretty much working : )

Check the documentation at:
http://digitarald.de/project/fancyupload/
and download src:
http://github.com/digitarald/digitarald-fancyupload

So what I do is I pass the COOKIE['symfony'] to the 'url' setting like:
url: $('sf_admin_edit_form').action + '".$sf_session."',

This is the url for the form action attribute.

Then I found a problem also with redirections from my module action (the upload worked but I was receiving "Server returned HTTP-Status #302"..). I solved this by not redirecting server-side but in the client-side settings of fancyupload:

//the 'response' in my case is the id from the database which I had to return to make the redirect complete..
onFileSuccess: function(file, response) {	

  parent.location.href = 'http://my.project.com/module/action/id/' + response;

},



Goodluck!

[Updated on: Tue, 22 June 2010 19:43]

Re: How to pass session id in URL? [message #103400 is a reply to message #28723 ] Mon, 02 August 2010 10:47 Go to previous message
SmallBen  is currently offline SmallBen
Messages: 21
Registered: September 2009
Junior Member
Thank's guys now it works fine Very Happy

[Updated on: Mon, 02 August 2010 13:14]

Previous Topic:[Help] - symfony command does nothing
Next Topic:Actions Class Corresponding To Global Layout (layout.php)
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software