Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-16-2008, 11:00 PM php Sessions
Junior Talker

Posts: 4
Trades: 0
I am trying to create an online game using php and MySQL (mainly).

I have a working registration and a working login, however I cannot figure out how to correctly use sessions for each user after login.

How I think this will work is :-

on login checks for valid loginname and password, if valid at the moment it displays
'Welcome $charname your dex is $dex and your str is $str'

Can anyone explain to me how to use variables so on login it creates a session, which will stay active until 10 minutes idle have passed. And can you also show me how to create session variables ie to display the dexterity of that character or the banked gold that character has on an interface.
NewbieDeveloper is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-16-2008, 11:24 PM Re: php Sessions
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Sessions are similar to cookies, but preferable in a lot of cases. Use session start to create a new session or to call an existing session, you can then use the $_SESSION superglobals to store data relivant to a particular user (not their password!)

Sessions will remain valid until a user closes their browser, but if you want to delete a session after 10 minutes just store the time when a user logs in, and then everytime they interact with the site just check to see if 10 minutes have transpired.

Sessions at php.net:
http://us2.php.net/session

Sessions tutorial:
http://www.w3schools.com/php/php_sessions.asp
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 03-16-2008 at 11:33 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-16-2008, 11:33 PM Re: php Sessions
Junior Talker

Posts: 4
Trades: 0
I have read the w3 schools one (where I learnt most of my coding knowledge from) and the other one I cannot figure either.

I don't want someone to write the entire code for me for the game, however I would like someone to throw me a starting piece of code I can study and see how it works in relevance with what I am trying to do.

Can you throw me a piece of code which creates a session and stores a dex variable char name strength etc.

I currently have this set as $dex = mysql SELECT and it does display Dex : $dex. I have no problems getting information from database into a variable or from inserting information into the database. The whole sessions idea I understand how it works but I do not understand how to code it correctly.
NewbieDeveloper is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 12:38 AM Re: php Sessions
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I can't really understand what problem you are having from your explanation, post whatever code you currently have and I will show you what you are doing wrong. Here is a really simple example of using a session:

PHP Code:
<?php
//page 1.php
session_start() //it is important to start a session before sending any headers
$_SESSION['dex'] = 'mysql SELECT';
?>

//page 2.php
<?php
session_start 
//retrieve the session
echo $_SESSION['dex']; //will output mysql SELECT
?>
I'm assuming that when you say $dex = mysql SELECT you mean a string.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 03-17-2008 at 12:39 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-17-2008, 04:24 AM Re: php Sessions
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Session is NOT similar to cookie because they both are different things. You cannot compare them like you cannot compare the soft and the sweet. Session is server-side data storage while cookie is client-side. They differ in style they store and provide data. Cookie can store the data itself like user login, time of last visit, preferred language, number of records per page and so on. But also cookie can store the session identifier which will start the server-side mechanism of session handling.

Session lifetime does not depend on time user's browser is open, it rather depends on length of time period between user's requests to server. If you leave your browser open for a whole day and the session lifetime is set to 1h it will most likely expire in 1h, but still it will depend on garbage collection settings.

You can certainly control only the lifetime of client's cookie with session identifier.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to php Sessions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16460 seconds with 12 queries