Jump to content

Regarding PHP sessions


new_to_php

Recommended Posts

Hi ,

I am implementing  seach functionality in a website.

Taking the keyword , search all the pages and storing results in result_array.

Results are displayed PAGE WISE. (like  PREV  1  2  3  NEXT)

If user clicks on "2" I am displaying  from result_array[10] to result_array[19] like that.

So I took result_array as session variable.

session_start();
session_register("result_array");

 

It is working fine , If I took 2 different browsers and test tha functionality on different browsers.

BUT problem is :

1. I open a browser (TAB1), open that website , give a keyword to search.

    Suppos it showed 30 results in 3 pages ( Prev 1  2  3 Next )

    Than , Open new TAB (TAB2) on same browser , open that website , give different keyword for search.

    suppose it shows 50 results in 5 pages  ( Prev 1  2  3  4  5 Next)

   

    NOW go to TAB1  .. Here problem comes , when I click on any page (suppose "2")

  result is over written by TAB2 results.

  I think it is becaues result_array is taken as session variable , how to solve it ?

 

  How to over come this problem.

 

Thank you.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/57228-regarding-php-sessions/
Share on other sites

Re-work your logic from the beginning. Your script is working as you made it, session variables are tied to the specific host and computer in which it is calling it, so if another file is outputting session variables that were assigned in a different file, as long as its the same host/client it'll be the same values.

 

One of the ways to fix your problem is to include the searched text on the page tabs, so it re-runs the query for every tab you choose. Or, you could have all of the pages/tabs outputted and you simply use javascript to navigate from one to the other (they would all be parsed out and unchanged that way).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.