Welcome Guest, Not a member yet? Register   Sign In
Sessions
#1

[eluser]RS71[/eluser]
Hello

I'm in need of some advice in regards to sessions. I'm thinking of having a search page and use sessions to store the search parameters that will be used in the results page.

I've read the user guide but how do sessions exactly work? The database version would be a session id stored in a cookie that is used to query the db to return the values? What about the other one? Is it a session id stored in a cookie that CI uses to read those session text files on the server?

What would be the best way to go about this? Which one of them is faster performance wise?

The thing that is complicated is that when you change any one parameter in the search form, the page instantly ajaxes and displays results on the side. If I use sessions, on every ajax request it would mean UPDATE then SELECT.

What do you guys think?

Thanks in advance.
#2

[eluser]pistolPete[/eluser]
Your explanation of the database use is correct, but the second one is not:
CI does not use native PHP sessions, so using only a cookie means that all of the data is put in the cookie instead of a serverside storage.

The use of the database is probably slower, but you could store more data than in the cookie.

Do you have to use sesssions at all for the search form? Isn't it possible to put the search terms in the URI?
#3

[eluser]RS71[/eluser]
Ah I see, thank you for your explanation.

I don't know why exactly I want to go the sessions route but it was the first option that came to my mind. The page that I have is a Google map with a side bar (results and filter). On every movement of the map, the script fetches a new xml file based on where the map is. (the xml is a php page that uses coordinates passed as uri segments)

I was thinking that by using sessions, the user could click on a result then travel back and be brought to the same place with the same results. If I used the URI segments, the javascript wouldn't remember the last place or search terms, no? I currently have the place of the map passed as URI segments but I'd probably set them in the session with the search preferences as well.

What do you think? Am I just talking non sense? heh
#4

[eluser]TheFuzzy0ne[/eluser]
Check out my post [url="http://ellislab.com/forums/viewthread/106502/"]here[/url]. I've devised a solution for coping with a variable number of arguments in the URI where the order might be unpredictable.
#5

[eluser]RS71[/eluser]
Interesting solution TheFuzzyOne.

I could be wrong but isn't there a solution to mix uri and get?

I think the problem I'd have is that if a user clicked on a result then went back, the page wouldn't go back to the last place since it was loaded via ajax.
#6

[eluser]TheFuzzy0ne[/eluser]
The URI and get (to my knowledge anyway), are the same thing.

I'm not sure I understand what you mean. If you're loading results via Ajax, the back button will take the user back to the previous page before anyway, would it not?
#7

[eluser]RS71[/eluser]
The page uses Google Maps API that loads a XML file. Depending on where the map is, the map loads a different XML (result set).

The user might move the map around and load different XMLs but he will still be in the same URL (ex. http://www.site.com/search/map). If the user clicks on a result page that leads him to (http://www.site.com/search/map/result) then clicks on the back button, the search page wouldn't know where he left off/what search parameters he used. This is where I think I'd use sessions. Would this be the right way to go?
#8

[eluser]TheFuzzy0ne[/eluser]
It depends.

For searching I sometimes use a two controllers, search and results.

Search will be where a form is posted to. It will process the form, and generate a URI. Then it will redirect the user to the results page, where the search function will extract the data from the URI, and display the appropriate result. Basically, the search function would turn your URL from something like this: http://mysite.com/search/map into something like this: http://mysite.com/search/map/country:UK/...ctions:yes etc...

My URI is hypothetical. I've no idea how the Google Maps API works, but hopefully you can see how to pass arguments via the URI using my library. It allows you to pass as many arguments as you wish, in any order you wish. This method also has the added bonus of giving users the ability to bookmark a map. Smile
#9

[eluser]RS71[/eluser]
Interesting thank you.

The map is constantly updating (on movement) so I'm not sure if I would keep redirecting the user to a different page on every change.

Which brings me to another somewhat unrelated thing (hehe):

My results are outputted as XML from a PHP page. Is there a way to prevent somebody from just going to the results page (ex: http://www.site.com/search/results/1) and keep changing the parameters and copying all the results.

What I mean is, prevent somebody from just going:

http://www.site.com/search/results/1
http://www.site.com/search/results/2
http://www.site.com/search/results/3
http://www.site.com/search/results/4
http://www.site.com/search/results/5

and so forth and just copying/'stealing' all the results.

Is there a way to make sure that the page is being requested from the search page itself?
#10

[eluser]TheFuzzy0ne[/eluser]
You can make it more difficult by generating a random has instead of a number. The CodeIgniter forum does this when you search.

You can use $this->input->server('HTTP_REFERER') to check where the user is coming from.

You can log the IP of the user who generated the results, and only allow access to the results from that IP address. (Only good for results that are kept for a short time).




Theme © iAndrew 2016 - Forum software by © MyBB