session & browsers (final) – PHP

  php

Q(Question):

I ask something relative later but the answer make me cry πŸ˜‰
If we duplicate the browser window (both in IE / Mozilla), both of 2 browser windows use the same session!!!
This produces many problems…

My program is this:
I have html format books inside zip files.
If I choose a book from my main page, php sets
$_SESSION[‘book’] = "a_book.zip";
and loads the index.html from a_book.zip.
if we click a link inside index.html like:
<a href=chapter1.html>Next</a>
Apache returns error 404, php handles this error and returns file chapter1.html from a_book.zip

All right but the problem is this:
If I duplicate browser window and in the 2nd browser I select another book, then because both of 2 browser use the same session, 2nd
browser change the $_SESSION[‘book’] and 1st browser searches in wrong zip file.

Any suggestions?

Regards
Gessos Paul

A(Answer):

"<- Chameleon ->" <ch******@hotmail.NOSPAM.com> a Γ©crit dans le message de
news: bn**********@nic.grnet.gr…

I ask something relative later but the answer make me cry πŸ˜‰
If we duplicate the browser window (both in IE / Mozilla), both of 2
browser windows use the same session!!! This produces many problems…

My program is this:
I have html format books inside zip files.
If I choose a book from my main page, php sets
$_SESSION[‘book’] = "a_book.zip";
and loads the index.html from a_book.zip.
if we click a link inside index.html like:
<a href=chapter1.html>Next</a>
Apache returns error 404, php handles this error and returns file
chapter1.html from a_book.zip
All right but the problem is this:
If I duplicate browser window and in the 2nd browser I select another
book, then because both of 2 browser use the same session, 2nd browser change the $_SESSION[‘book’] and 1st browser searches in wrong zip
file.
Any suggestions?

Regards
Gessos Paul

sorry for makin’ you cry πŸ™‚

for your problem, maybe you should try to use a random ID (or book name if
unique) for each search made on your Zip or something like that.
You should add something in your session to identify which book you’re
using.
something like :
$book["RANDOM_ID"]["BOOK"]
$book["RANDOM_ID"]["OTHER_VAR_RELATED_TO_THIS_BOOK"]

You’ll need to write a script to manage those vars and crush the session
var.

hope it’ll help
Regards,
Julien.

A(Answer):

> > I have html format books inside zip files.

If I choose a book from my main page, php sets
$_SESSION[‘book’] = "a_book.zip";
and loads the index.html from a_book.zip.
if we click a link inside index.html like:
<a href=chapter1.html>Next</a>
Apache returns error 404, php handles this error and returns file chapter1.html from a_book.zip

All right but the problem is this:
If I duplicate browser window and in the 2nd browser I select another

book, then because both of 2 browser use the same session, 2nd

browser change the $_SESSION[‘book’] and 1st browser searches in wrong zip file.

for your problem, maybe you should try to use a random ID (or book name if
unique) for each search made on your Zip or something like that.
You should add something in your session to identify which book you’re
using.
something like :
$book["RANDOM_ID"]["BOOK"]
$book["RANDOM_ID"]["OTHER_VAR_RELATED_TO_THIS_BOOK"]

You’ll need to write a script to manage those vars and crush the session
var.

Thank you for your response, but I don’t understand. Sorry ;-(
first of all book name is unique. I have 2 browser windows:
1st has $_SESSION[‘book’] = ‘php_manual.zip’
2nd overide $_SESSION[‘book’] = ‘thinking_in_cplusplus.zip’ because has the same session
so when 1st gets image: image.jpg from an <A> tag, php search inside ‘thinking_in_cplusplus.zip’ and not inside ‘php_manual.zip’

You suggest $_SESSION[‘book’] will be an array? How it help?
thank you

A(Answer):

On Thu, 30 Oct 2003 17:38:18 +0200, <- Chameleon -> wrote:

Thank you for your response, but I don’t understand. Sorry ;-(
first of all book name is unique. I have 2 browser windows:
1st has $_SESSION[‘book’] = ‘php_manual.zip’
2nd overide $_SESSION[‘book’] = ‘thinking_in_cplusplus.zip’ because has the same session
so when 1st gets image: image.jpg from an <A> tag, php search inside ‘thinking_in_cplusplus.zip’ and not inside ‘php_manual.zip’

You suggest $_SESSION[‘book’] will be an array? How it help?
thank you

He’s saying that you need to use a unique identifier for each book OTHER
than the generic name ‘book’. (Also note that the session for a browser
and ALL of its open windows is the same session.)

So if book names are unique, track the book by using the name of the book,
instead of the very generic variable name "$book".

Something like

$_SESSION[‘book_list’][‘a_book’] = ‘a_book_file.zip’;
$_SESSION[‘book_list’][‘b_book’] = ‘b_book_file.zip’;
$_SESSION[‘book_list’][‘c_book’] = ‘c_book_file.zip’;

etc…

That makes an array $_SESSION[‘book_list’]. Use that array to keep all
the books in one place, but use a different key for each book, in this
case the key is the book’s name.

Hope this helps. If not, then learn more about Arrays, Multi-dimensional
arrays, Associative arrays, and Sessions. Go to
http://www.php.net/manual/ for that.

later…

Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

A(Answer):

> He’s saying that you need to use a unique identifier for each book OTHER

than the generic name ‘book’. (Also note that the session for a browser
and ALL of its open windows is the same session.)

So if book names are unique, track the book by using the name of the book,
instead of the very generic variable name "$book".

Something like

$_SESSION[‘book_list’][‘a_book’] = ‘a_book_file.zip’;
$_SESSION[‘book_list’][‘b_book’] = ‘b_book_file.zip’;
$_SESSION[‘book_list’][‘c_book’] = ‘c_book_file.zip’;

etc…

That makes an array $_SESSION[‘book_list’]. Use that array to keep all
the books in one place, but use a different key for each book, in this
case the key is the book’s name.

Hope this helps.

Thank you but it is wrong πŸ˜‰
Wrong because you want a key (the book’s name).
Where can I store this key? In Session? In this case we fall in the start of the problem.
I cannot use GET, POST & COOKIE

A(Answer):

On Thu, 30 Oct 2003 21:44:33 +0200, <- Chameleon -> wrote:

Thank you but it is wrong πŸ˜‰
Wrong because you want a key (the book’s name).
Where can I store this key? In Session? In this case we fall in the start of the problem.
I cannot use GET, POST & COOKIE

You lost me there. Why can’t you store the book’s name in a session?

Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

A(Answer):

> > Thank you but it is wrong πŸ˜‰

Wrong because you want a key (the book’s name).
Where can I store this key? In Session? In this case we fall in the start of the problem.
I cannot use GET, POST & COOKIE

You lost me there. Why can’t you store the book’s name in a session?

because 2nd browser windows which points in other book will overide 1st browser book’s name.

anyway, I found other method to accomplish:
Until now I dont knew that:
I can pass data with GET with this:
book.php/thinking_in_cplusplus.zip/index.html

All are easy now

thanks

LEAVE A COMMENT