Nov 22, 2009

Sessions, Setting, Unsetting, Reading - and in combination w/ cookies

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Sessions, Setting, Unsetting, Reading - and in combination w/ cookies

frenz
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

Comment/Reply (w/o sign-up)

minnieadkins
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

 

 

 


Comment/Reply (w/o sign-up)

Quatrux
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

Comment/Reply (w/o sign-up)

frenz
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.

Comment/Reply (w/o sign-up)

Hercco
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.

Comment/Reply (w/o sign-up)

vhortex
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..

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Sessions Setting Unsetting Reading Combination Cookies

  1. Reading Xml Data - Within PHP (2)
  2. Php, Sql Lite: Storing Session's Data? - how so store session in SQLITE? (1)
    normally, in windows, session data is saved in the location as directed by the "session.save_path"
    directives. they only show how to store session data in file. is it possible to store it inside the
    SQLite? anyone?...
  3. Reading Files And Folders - (1)
    I am in the process of writing a small content management system for my niche sites and need to be
    able to accomplish the following two items. Any assistance would be appreciated: I have a
    directory that has nothing but sub directories in it and I need to be able to identify each
    directory name and return them in an option drop down selection menu which will be included in an
    identifying URL. ALSO: I am in need of a script that could be included on a returned page
    that will read the content of a table and identify various keywords within the content and pl...
  4. Already Sent Session Cookies? - (2)
    Er, this is the second topic I've posted about session problems. Here's the html file that
    keeps showing up: CODE Warning: session_start() : Cannot send session cookie - headers already
    sent by (output started at C:\Program Files\xampp\htdocs\index2\loggingin.php:2) in C:\Program
    Files\xampp\htdocs\index2\loggingin.php on line 39 Warning: session_start() : Cannot send session
    cache limiter - headers already sent (output started at C:\Program
    Files\xampp\htdocs\index2\loggingin.php:2) in C:\Program Files\xampp\htdocs\index2\loggingin.php on
    line 39 Fatal ...
  5. Php Forum Cookies - I need help on a php forum cookie. All suggestions welcome. (3)
    OK, I am making a forum in php (with a mysql database). It is much harder then I thought it would be
    but I have been getting along very well. I was just putting some finnishing things on it when I
    found a problem I couldn't figure out. All suggestions are welcome. Problem: I want my forum
    (like all forums) to remember what topics you have already read. I want to do this via cookies and
    at first I was think of having to topic ID to be saved in a string. Example (Cookie:
    %x%) x=the forum topic ID. Then to retrieve that data I would simply look for %x% inside the coo...
  6. I'm Having Problems With Sessions - (2)
    I haven't really read much about sessions, i usually study PHP by viewing other's codes and
    learning from it. Here's what keeps on popping out when I open the page. CODE Warning:
    session_start() : Cannot send session cookie - headers already sent by (output started at
    C:\Program Files\xampp\htdocs\maple-radio-live\loggingin.php:7) in C:\Program
    Files\xampp\htdocs\maple-radio-live\loggingin.php on line 40 and CODE Warning: Cannot
    modify header information - headers already sent by (output started at C:\Program
    Files\xampp\htdocs\maple-radio-live...
  7. Reading Data From Sessions - (2)
    Hello everyone! Before I start let me just say that ive read many threads on here about php and
    sessions, several tutorials and the php manual but I still cant find a solution to my problem. My
    problem is that when i try to read data from a session it just comes up blank, and an if statement
    to see if the variable is null returns true. The code im using is for a login script which checks
    the input from a user and compares it with the data in a database to log the user in, this works
    fine, also reading the data from the session works perfectly on the page which the sess...
  8. PHP Sessions, Help - how to use sessions? (4)
    hey buddies need help with sessions( PHP ) how can i use them, with or without SQL ? i tried some
    scripts, but didn't work. and since passing the SID with URL is stupid and ugly, help me plz .
    thank ya...
  9. Possible To Do? - Reading a remote website's data .. (7)
    What I need to know is how to do the following? I'm completely confused, although I sort of
    have a general feel of what I need to do, I just have no clue how to do it. I need to be able to
    take some data from one page, displayed on their site as an HTML table, and then output certain
    pieces of it to my site. I will disclaim here and now that what I intend to do does not violate
    any laws, as I'm not stealing a persons content. I am using this to act as an online counter, to
    see how long someone is online. I also have emailed the company to ask if what I'm...
  10. Php Reading And Writing To File - the code is very esay (4)
    this code to Read from file you can use this code in to make a small data base and it is very to
    use CODE $fp = fopen ("file.txt", "r"); $bytes = 4; $buffer = fread($fp, $bytes); fclose
    ($fp); print $buffer; ------------------- to write to same file CODE $fp = fopen
    ("file.txt", "w+"); fwrite ($fp, "Test"); fclose ($fp); ---------------- thanks and iwait the
    commant...
  11. Php Sessions - I don't really get it... (4)
    Are php sessions unique for each site? If my site gave a session named "abcd" to a user, but he/she
    already has a session called "abcd" on another site, is it going to replace the one on the other
    site, or are those two not recognized as the same on the user's computer?...



Looking for sessions, setting, unsetting, reading, combination, w, cookies

See Also,

*SIMILAR VIDEOS*
Searching Video's for sessions, setting, unsetting, reading, combination, w, cookies
advertisement



Sessions, Setting, Unsetting, Reading - and in combination w/ cookies

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com