Sessions and fopen()

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
joncampbell
Forum Newbie
Posts: 24
Joined: Fri Mar 11, 2005 12:57 pm
Location: Irvine, California, USA

Sessions and fopen()

Post 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,
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post 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.
User avatar
playgames
Forum Newbie
Posts: 22
Joined: Tue Sep 04, 2007 4:28 am

Post by playgames »

require file have session_start() yet?

fopen as a string not v.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Sessions and fopen()

Post 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?
joncampbell
Forum Newbie
Posts: 24
Joined: Fri Mar 11, 2005 12:57 pm
Location: Irvine, California, USA

Post 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,
Post Reply