Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2003, 02:34 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi Royce,

BTW: This code depends on the server being one and the same. After reading Nik's response it dawned on me about the IP addresses being different. Doesn't necessarily mean that there are two completely different PHP's running it though. Nor does it necessarily mean that there are two different servers. To find that out for sure check with your ISP's technical support.

I know that my secure and non secure url reference the same IP address.. I am luckily fortunate enough to have an ISP with the vision and understanding that a programmer may *need* all of that to be the same in order to make use of the SSL feature. But often times the secure server is separate from the regular server.

If the ini setting doesn't do anything for the problem.. come back to us and we can dream up a custom session handler. I've been curious about how to it anyway!

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old September 14th, 2003, 02:17 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to roycehart
Default

Hello Rich and Nik,

First of all, thanks for your thoughtful, clear, and rapid responses. Your collective insight is making this problem appear manageable. :D

Rich - I am going to test out the code you prepared and see what the results are.

Nik - the site I am developing has a dedicated IP address, with a second dedicated IP for the "secure" subdomain. I am currently hosting about 60 relatively dormant domains on this server, only a handful of which have dedicated IP's.

I have root access to this server, so I _can_ make configuration changes. However, I would rather make the code in each of my domains self-contained enough that I won't have to mess around with the .ini settings every time I build a new cart or make other mods.

I will touch base with you as soon as I see the results from the code you sent.


 
Old September 14th, 2003, 02:58 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to roycehart
Default

Rich - I have tested your code for submitting variables via the POST method, and it works as expected.

What I attempted to do last night was to pass the insecure SID via the GET method to the SSL-secured page. I then tried to overwrite the new SID (created when the new secure connection was initiated) with the insecure SID by using the session_id() function.

Admittedly, I didn't echo everything to see what was really going on, but I queried the database and found that a new SID had been created. Also, the once-full shopping cart was reported as empty (indicating that the new, secure SID was in effect).

I'll be working on this for about another hour and then I'll be away until late evening.

Thanks again,

Royce



 
Old September 16th, 2003, 11:42 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

The code provided for altering the ini directive *should* be done at
runtime, as each hosted domain isn't going to have the same needs. This
would make no sense if it were done at the root level. And this can be
designed to be ambiguous.. meaning that it can update itself to fill the
need whenever this situation presents itself in the future. And should in
theory correct the problem of new session id initiation. So this would
eliminate the need for any configuration changes at the admin level,
provided that the same installation of PHP is running both the secure and
non-secure sites thereby transcending different IP addresses and even
completely different sites all-together, the non secure domain and
subdomains can be designed to share session with the central SSL. To make
it truly ambiguous I would suggest plugging in a $_SERVER or $_ENV variable
that contains only the domain and suffix, which would allow the SSL to
accept refering sessions from either the non secure domain or its
sub-domains in any situation where there is the need to transfer the session
from one of these to the SSL domain.

Essentially you are saying to the server, allow this referring url to be one
in the same with the current as far as sessions go. And this is a tiny
amount of code and effort when compared to the alternative, creating a
custom session handler. Which in my mind I would see as the only other
solution, without serious changes to how the system is set-up.

Also, just in case there were any misunderstandings as to what ini_set()
does, this change is not permanent. It only alters the ini setting for the
lifetime of the script. So this function does not actually change
configuration in the ini file.

After looking over your responses again I was wondering if that thought had
crossed your mind.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old September 16th, 2003, 11:48 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:
Hi Rich,

I apologize; when I see anything in PHP that refers to the term "ini" I
immediately think of php.ini. In other words, my mind turns to things that
are server-wide and permanent (insofar as configuration issues are
concerned). I realize now that ini_set() is a function that pertains only to
the script at hand.

Per my other email, I have a LOT of reading to catch up on to converse
intelligently about this.

You have given me a lot to go on, and I'm going to have to read more to
understand it more fully. I think I might have done better to post to the
beginner's PHP section; I was just afraid that the problem was more advanced
than that and wouldn't be responded to there.

Thanks again for your help. I'll be back in touch when I have a firmer grip
on the workings of all this.

Thanks for your patience and clear explanations,

Royce
No problem. PHP is a complex language! Well the forum doesn't really matter, we're likely to assume more knowledge if you post the the pro forum. But in the end it'll all come out anyway!

: )
Rich



:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old September 16th, 2003, 06:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Keep in mind that writing code that alters configuration settings at run-time can only work if PHP is set up to allow those run-time changes.

Also, keep in mind that writing custom session handlers is not that difficult! If you continue to use cookies to store the session ID, you can prevent ALL The headaches you've been suffering with by specifying the domain of the cookie to encompass ALL of your sites, not just a specific one!

There are six functions you need to write in order to implement custom session handling: open, close, read, write, destroy, and garbage collection. There's already lots of decent documentation and tutorial material out there. I'd suggest starting with the PHP manual at:
  http://www.php.net/session_set_save_handler

There are also several decent tutorial articles at PHPBuilder.com:
  http://www.phpbuilder.com/

Here's a good start, though a bit outdated:
  http://www.phpbuilder.com/columns/ying20000602.php3


Finally, in defence of posting in the Pro PHP forum, it was me that started this thread. I just wanted a TIP/FAQ type posting about why session_register() is bad, and wasn't really expecting a new, albeit related, thread to be appended to it a couple months later! =)


Take care,

Nik
http://www.bigaction.org/
 
Old November 21st, 2004, 12:21 AM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by nikolai
...

If both servers use the same database back-end, you should write custom session handlers so all your servers pull session data from the same source. You'll have to be careful how you generate session IDs, though. You can't count on an IP address because anyone behind a NAT firewall will share the same session for your site.
Hey Nik, I'm struggling with the same problem, and I'm comfortable coding my own session handler to a database, but it's not clear to me how this will help since I don't see where in the API for the sesssion handler I'm supposed to be generating my own SIDs. It looks to me that the keys for the read and write calls are generated by php, and I'm afraid that in the hash algorithm for creating keys for the session routines includes the domain of the referer as a seed, and thus will still be different between $_SESSION arrays created from SSL-accessed page and those on my non-SSL pages with a different root domain. I'm sure I'm missing something obvious....

-George

 
Old November 21st, 2004, 09:35 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Unfortunately, what I suspected appears to be the case: I implemented a db-backed session handler, so different servers on the backend access the same place to retrive session info. The problem is that different session keys are generated from the page accessed from the SSL url than those accessed from the non-secure URL. So implementing the session handler, while i suppose is nice for use in a cluster, doesn't by itself solve this problem. I'm still poking around trying to figure out how to take over the generation of session id itself (that appears to be the $key that is passed into the session's read and write handlers). If anyone has any pointers, or if you think I'm barking up the wrong tree, please shout. Thanks a bunch.

-George Snelling






Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad Connection String paulcbyrum Access VBA 3 May 9th, 2008 09:19 PM
Very slow and almost no replies...BAD..!!! zach007 Forum and Wrox.com Feedback 4 December 23rd, 2006 06:48 PM
Bad SQL in Try It Out in chapter 3 punch BOOK: Beginning SQL 1 August 18th, 2006 06:39 PM
Bad Data Error chiefg General .NET 1 March 4th, 2006 03:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.