Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Sessions, Setting, Unsetting, Reading, and in combination w/ cookies
frenz
post Mar 31 2006, 12:04 PM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 30-March 06
Member No.: 12,355



I am making a login script which atm uses a cookie to set login status.

I would like to include sessionwise checking into this. And also an IP check, where i write the IP to database and later get it for all other pages and then check it up to the client for each page.

I need to know the commands for:
- getting an IP
- Starting a session
- Ending a session
- Reading a session
Go to the top of the page
 
+Quote Post
minnieadkins
post Mar 31 2006, 06:04 PM
Post #2


Premium Member
Group Icon

Group: Members
Posts: 292
Joined: 15-December 04
Member No.: 1,768



QUOTE(frenz @ Mar 31 2006, 07:04 AM) *

I am making a login script which atm uses a cookie to set login status.

I would like to include sessionwise checking into this. And also an IP check, where i write the IP to database and later get it for all other pages and then check it up to the client for each page.

I need to know the commands for:
- getting an IP
- Starting a session
- Ending a session
- Reading a session


IP Address
Getting User's IP - Use $_SERVER['REMOTE_ADDR'] variable
Sessions
Sessions seem to have been discussed quite a lot in this forum.
Naming A Session - use session_name('sessionName') to name your sessions whatever you want
Starting - Basically include session_start() on all of your pages in order to maintain an open session.
Reading Session - Use $_SESSION['variableName'] to either set or read your session variables
Ending Session - many ways to do it, whatever works for u...example below
CODE

$_SESSION = array(); // clear the universal variable to make sure
    if (isset($_COOKIE[session_name()])) {
        setcookie(session_name('SessionName'), '', time()-42000, '');
    } // clobber the cookie if there is one
    session_destroy(); // purge the session record
    session_write_close();// not too sure about this <- someone can elaborate

That should do the trick with ending it, or at least it does for me.

Take a look at this thread as it has been already discussed in detail here http://www.astahost.com/php-sessions-help-t10348.html
Go to the top of the page
 
+Quote Post
Quatrux
post Mar 31 2006, 07:04 PM
Post #3


the Q
Group Icon

Group: [HOSTED]
Posts: 1,133
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059
myCENTs:3.82



to that session ending script you pasted in Code, before the session_destroy() you could add session_unset() if you want to make it even better, but this is quite insane in my opinion. Anyway, just make sure that the session does not recreate after the logout or whatever you want. And be careful using sessions, I mean the session super global $_SESSION and the choice of its names, because of the registered globals on/off, which makes a lot of headache. wink.gif
Go to the top of the page
 
+Quote Post
frenz
post Apr 2 2006, 02:04 PM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 30-March 06
Member No.: 12,355



Thanks for the info, im gonna use a mixture of all the methods to make a secure login script for my own page which has a news-system and a CMS, and i have made it all myself, and i think i shall finish it myself

But i need some input on general login scripts, the layout.
Go to the top of the page
 
+Quote Post
Hercco
post Apr 5 2006, 07:51 PM
Post #5


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



QUOTE(Quatrux @ Mar 31 2006, 10:04 PM) *

to that session ending script you pasted in Code, before the session_destroy() you could add session_unset() if you want to make it even better, but this is quite insane in my opinion.


I don't thats insane. That's actually quite sane thing to do. session_destroy() does not unset the variables, it just destoys the data. There is a difference.



QUOTE(Quatrux @ Mar 31 2006, 10:04 PM) *

Anyway, just make sure that the session does not recreate after the logout or whatever you want. And be careful using sessions, I mean the session super global $_SESSION and the choice of its names, because of the registered globals on/off, which makes a lot of headache. wink.gif


Registered globals makes a lot of headache. Perioid. smile.gif I strongly recommend everyone be it admin or web developer to go for registered globals off. I condired scripts that require registered globals on such a garbage that they deserve not to work.
Go to the top of the page
 
+Quote Post
vhortex
post Apr 6 2006, 12:35 PM
Post #6


Guilty Until Proven Innocent
Group Icon

Group: Members
Posts: 372
Joined: 13-April 05
Member No.: 3,937



QUOTE(Hercco @ Apr 6 2006, 03:51 AM) *

Registered globals makes a lot of headache. Perioid. smile.gif I strongly recommend everyone be it admin or web developer to go for registered globals off. I condired scripts that require registered globals on such a garbage that they deserve not to work.


for me too, turn the register globals thingie off permanently..
pages created with register globals as off is way much secure ang stable that the register globals on modes.

---

i never forget to unset the session before destroying them. they produce strange effects on the server and scripting engine if they are not closed and destroyed.

some versions of php/apache allows me to destroy a session then unset while others just hang by using this commands in this order..

to place safe. i have put a small include file on all pages that unset all sessions and destroy them on the fly..
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php, Sql Lite: Storing Session's Data?(1)
  2. Possible To Do?(7)
  3. PHP Sessions, Help(4)
  4. Reading Data From Sessions(2)
  5. I'm Having Problems With Sessions(2)
  6. Already Sent Session Cookies?(2)
  7. Php Forum Cookies(3)
  8. Reading Files And Folders(1)
  9. Reading Xml Data(2)


 



- Lo-Fi Version Time is now: 4th December 2008 - 10:56 PM