|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Message-driven game: sessions variables and include problems
Hello all,
I have a question regarding a coding problem that I can't seem to fix. I am creating a message-driven RPG site. Coding PHP is a new hobby, so I apologize if not all code is as optimal as it could be .The site is based around a template page (index.php). It contains a navigation menu and loads content by including the required pages. Default content is an introduction page. Also index.php facilitates user authentication, by means of a login form. The coding problem relates to session variables being lost when browsing around the site. index.php -> all_matches.php -> view_match.php -> add_post.php The player logs in on index.php (a login form is located there), then browses to all_matches.php where he selects a match where he wants to post. In view_match.php, the selected match is displayed. I want to display a hyperlink in view_match.php to an 'add post form' (add_post.php). But this hyperlink may only be displayed if the player is logged in and is authorized to post in the match. Of course, I later check this again in add_post.php for security reasons. Index.php creates a session with the $Name (user name), $access (allowed access) and $login (set to 1 if logged in). Because the template page stays the same, the data is retained. When going to all_matches, session data is retained. But when I go to view_match, session data is lost. Remember that all_matches.php, view_match.php and add_post.php are all loaded as content in index.php! If anyone knows how to solve this problem, I am eternally grateful. Note that I use session_register, instead of $_SESSION. This isn't the problem as on the other pages it works. But I'll probably change this in the future. Some excerpts of the scripts are below. Index.php: ========== PHP Code:
All_matches.php: ================ This page gives an overview of all available matches. The only important thing here is the link to view_match.php. The variable $details['match_id'] is retrieved from a MySQL database. PHP Code:
View_match.php: =============== PHP Code:
Conclusion: =========== I always get "No access specified!" in view_match.php, I don't know why. Perhaps, this is because the code [include $b_url.'view_match.php?m='.$mid;] in index.php is an absolute URL and PHP drops the session for security reasons ???? Any help is appreciated. Thanks for reading this far. |
|
#2
|
||||
|
||||
|
Ever since they included the new 'superglobals', I've stopped using functions like 'session_register'
A much easier, and in my experience reliable, way to handle session vars is simple store and retrieve them from the $_SESSION[] superglobal. If you want to store something in your session: $_SESSION['varname'] = $varname; or $_SESSION['varname'] = value; to retrieve them: $varname = $_SESSION['varname']; A note on this: if register_globals is enabled on your server, the 'retrieval code' is not necesary. However, for security reasons, it is very unwise to rely on this. (Depending on server settings, people may overwrite your session variables with GET variables). This is also probably where your code goes wrong: You assume $Name, $login and $access are registered automatically, but when register_globals is off, this may give trouble. Personally, I never even use local versions of session variables. Whenever I need a variable that's in a session, I use the $_SESSION variable there.
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 280
![]() Last edited by Itsacon : February 4th, 2005 at 07:06 AM. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Message-driven game: sessions variables and include problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|