Jump to content

which is better, Session or Cookies?


abdfahim

Recommended Posts

Hi, plz tell me which is better process for user login in a website, Session or Cookies. If Cookies is better, then plz give any link where I can find easy and vivid knowledge for implementing cookies login system in my site. Btw, at present I am using Session for login system in my site.

Link to comment
Share on other sites

Hi, please tell me which is better process for user login in a website, Session or Cookies. If Cookies is better, then please give any link where I can find easy and vivid knowledge for implementing cookies login system in my site. Btw, at present I am using Session for login system in my site.

I'm pretty sure all the php forums use sessions for the login, you can use cookies for remembering a username in the input box but I'd say Session is best for actual login.

Link to comment
Share on other sites

thanx guys for your comments. plz help me a bit more.

 

The problem is, whenever I login in my site and do nothing for some time (like 1 minute), it automatically logged out. So, after some time, when I wanted to go to another page, it again ask to login.

 

I want that, as long as browser is open, or some one intentionally logged out, he remains log in. To do that, which session function should I use? At present, I use nothing but Session_Start.

Link to comment
Share on other sites

I am agree with Petty_Crim.

I always use sessions for my login pages.

Session is preferred by all php developers.

 

Would you then explain to me how you would keep the user logged in even AFTER they've closed the browser? That can only be done using cookies. Besides, how can you say that all PHP developers prefer sessions?

Link to comment
Share on other sites

I prefer cookies.

The only downfall in them is you have to either encrypt the data or use a special way to identify them.

And then also you can set them for how long you want and they will stay until that time.

Link to comment
Share on other sites

Would you then explain to me how you would keep the user logged in even AFTER they've closed the browser? That can only be done using cookies. Besides, how can you say that all PHP developers prefer sessions?

 

1st of all every body if u r a programmer would know what is session and what is cookie,

It depends on the person either he want to store the data on client pc or not. i will not store personally.

I say "that all PHP developers prefer sessions" It does not mean that you, if you dont want to store it in sessions, use cookies.

That was my opinion.

Every body know (who know session and cookies) that after closing browser the session data is destroyed , cookie one remain.

I did not say the session store the info after closing browser, I say that depends on the person.

Hope u will understand what i want to say.

Link to comment
Share on other sites

I prefer cookies.

The only downfall in them is you have to either encrypt the data or use a special way to identify them.

And then also you can set them for how long you want and they will stay until that time.

Now it depends on the person who prefer which one.

As Deathstar describe,

cookie are more vulnerable u have to use secure way to protect cookies, while sessions are a little bit secure than cookies.

Now if some one use that pc and enter to the login pages for a that user who store his information cookies than???

 

Link to comment
Share on other sites

Yes Deathstar i am agree with you 1st of all if some one want to use session or cookies he or she must know what is the function of both,

I know that where it is saving temporary their files(Php temp folder). Also u can change that to ur desire folder using php.ini session_save_path, something like that in php.ini.

Link to comment
Share on other sites

Dear mmarif4u, I have an information for you. I have Apache 2.0.54, php 5.2.3 and mysql 4.1.20 installed in my PC. I never face any problem when testing in my PC. But when I upload my files in the server (configuration: mysql 5.0.41, php 5.2.3), the session automatically expires after some time whether I close the browser window or not. Now what may be the problem?

Link to comment
Share on other sites

It depends on ur scripts, whether u use cookie or sessions.

If sessions i think i already mention that change ur script a little bit to work properly.

As code i write in previous posts.

Just try on 2 or 3 pages not on all if u have alot of pages to edit.

If that works than change ur scripts step by step to work properly.

If this does not work than please post the code any one of the pages .

we will try to solve ur problem.

If have local machine running these softwares then try on that dont try it 1st on live server, this is my suggestion.

Bcoz i test my pages locally 1st, if it works than i upload to live server.

Hope this will help you a little.

Regards

Link to comment
Share on other sites

well, its seems a very interesting topic, i do have a question friends,  i have some weird problem using sessions.

 

sessions always rejects my first login attempt and and on IInd attempt with same login details i can loginin. I am not sure if i am only person having this problem.

 

 

Link to comment
Share on other sites

Dear mmarif4u, I have an information for you. I have Apache 2.0.54, php 5.2.3 and mysql 4.1.20 installed in my PC. I never face any problem when testing in my PC. But when I upload my files in the server (configuration: mysql 5.0.41, php 5.2.3), the session automatically expires after some time whether I close the browser window or not. Now what may be the problem?

 

Your server must have a different session maxlifetime setting that on your PC.

 

Look for session.gc_maxlifetime in your php.ini - make the settings identical on your server and PC, then your PC testing will be a more accurate representation of what you will get on your server.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.