Page 1 of 1

Sessions and fopen()

Posted: Sun Sep 16, 2007 3:27 am
by joncampbell
I have a php file I am using that is accessing 2 other php files using fopen(), I have a singleton session class, which I use in all 3 php files, when I load the main php file that loads the other 2 files, I only have 1 session active, and all 3 php files are using this session, when I use a post submit button to one of the 2 fopen()'ed files it switches to a different session.

Do you guys think this is happening because the $_SERVER['REMOTE_ADDR'] and $_SERVER['REMOTE_HOST'] are my server when I am using fopen(), and when I am using the post redirect it is using my local computers $_SERVER['REMOTE_ADDR'] and $_SERVER['REMOTE_HOST']?

If you need some code examples to understand what I am asking, please ask. :)

Thanks again for all the help,

Posted: Sun Sep 16, 2007 4:31 am
by Mordred
It sounds like you've nailed the problem already.
A possible solution would be to encapsulate the code in the PHPs you currently fopen() in functions, and then call the functions from your user-accessible script.

Posted: Sun Sep 16, 2007 6:56 am
by playgames
require file have session_start() yet?

fopen as a string not v.

Re: Sessions and fopen()

Posted: Sun Sep 16, 2007 6:59 am
by volka
joncampbell wrote:I have a php file I am using that is accessing 2 other php files using fopen()
To change the php code in that two files? When, where and why?

Posted: Mon Sep 17, 2007 2:00 am
by joncampbell
yes, I could call the functions from those classes, but let me give you a little more information to see if this could help you guys come up with more creative answers.

I have 2 php scripts that I created, that are web services, one provides metrics information for the current programming projects I am working on in either xml or xhtml, the other provides news information, like what is happening around the world, and it is also a web service.

I am using the fopen() set of commands to read from these 2 scripts, as they provide xml or xhtml with a GET or POST method, and are self sustaining, the thing that is not wroking correctly is that when you use fopen() or file_get_contents the current executing script uses the identity of the web server and not the visitor to the page, so when I first access these 2 scripts they have a different session ID then when I access them from my browser, I think this is not the correct behavior that most people would want, and I think that this should be corrected in further versions.

As I can not wait for further versions of php that fix this problem I need a work around, I know how to set the "HTTP_USER_AGENT" string to the same one as the visitor, but I am having trouble setting "HTTP_ADDR" to the address of the visitor, can anyone offer some suggestions other than the obvious suggestion, which would be to alleviate the hard work I have done to create these self sustaining applications and make one super application that had to call all these classes individually, I know someone in this forum has had to over come this problem in the past, this seems like a vital process of making "Very Dynamic Pages".

Again, I am very appreciative of the help that this forum gives, and that the community has donated to me over my career,