473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Game Site

Hello all,

I've been slowly creating a text-based game site for a while now when I have time....

The site has a lot of JavaScript and usually downloads info from the MYSQL database on page load then uses equations to predict what the server value will be after a certain time...

This approach may cause problems when if the user logs in on multiple browsers as they will be able to cause changes in their account but the other browsers will not have detected this unless they are refreshed.

My question is how could i stop the user logging in on multiple browsers? I was thinking of something like a random variable is generated on login. Stored in a JavaScript variable and in the database. all interactions need this and if they then log in on another browser the variable on the server is updated so the new window can access the server but now the old browser has wrong code and can not.

The only problem with that is it will only show as being invalid on an action from the user on the old browser. Would be nice if there was a way for it to pop up on the old browser that he/she has been logged out due to logging in on the new browser as it happens.

:D

Probably impossible?

I also understand it’s debatable whether this is actually a MYSQL question.

Thanks in advance for any insight.
Jun 29 '09 #1
2 1678
Atli
5,058 Expert 4TB
Hi.

You could avoid this problem altogether by firing AJAX calls every few seconds (or whatever) to check if there have been any updates.
Simply record the time whenever you update the info in the database, have AJAX fetch that time every now and then and compare the new time with the time when the page, or last update, was loaded.
If the time is newer, have AJAX fetch the updated data and update the page.

If you want to restrict the user to a single login in a single browser you could do what you suggested; generate a random key that the client must pass whenever an update is requested.
Then you could have AJAX pass the key to the server every now and then (perhaps with the status updates), and have the server validate it. If it fails validation, the client is denied access to the server.
Jun 29 '09 #2
Yeah, I'm just very wary of using too many AJAX requests as if there are a few logged in it may cause load issues. I could send the key perhaps every 2 mins with the time resync.

What are your thoughts on this code? Its my main script and it page has 3 functions called getPage.. and the template files has similar. The idea being that each page would have had a bulk of code (now in template) that was duplicated this way template script is only in one file.

I could probably do that check somewhere in here but this is only executed on page refresh. :S

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ob_start(); //Buffer all output.
  3. session_start();//Start global session.
  4.  
  5. require("PHP/TemplatePHP.php"); //Website template
  6. include("PHP/dbCon/config.php"); //Required for db connection
  7. include("PHP/dbCon/opendb.php"); //Required for db connection
  8.  
  9.  
  10.  
  11. //Check if user is logged in.
  12.  
  13.  
  14. if(isset($_GET["page"])){$inPage="PHP/". $_GET["page"] .".php";}
  15. else{$inPage=null;}
  16.  
  17. if(!isset($_SESSION['username']))
  18. {
  19.     if($inPage == "PHP/Register.php")
  20.     {
  21.         $outPage = $inPage;
  22.     }
  23.     else
  24.     {
  25.         $outPage = "PHP/Login.php";
  26.     }
  27. }
  28. else
  29. {
  30.     if(file_exists($inPage))
  31.     {
  32.         $outPage = $inPage;
  33.     }
  34.     else
  35.     {
  36.         $outPage = "PHP/Error.php";
  37.     }
  38. }
  39.  
  40. include($outPage);
  41.  
  42. tempPageP1(true);
  43.  
  44. //Header additions (JS)
  45. getPageJS();
  46. //Header additions (CSS)
  47. getPageCSS();
  48.  
  49. tempPageP2(true);
  50.  
  51. //Page Title
  52. getPageTitle();
  53.  
  54. tempPageP3(true);
  55.  
  56. //Message to user.
  57. if(isset($_SESSION['message']))
  58. {
  59.     echo "<p id=\"userMessage\">{$_SESSION['message']}</p>";
  60.     unset($_SESSION['message']);
  61. }
  62. //Page body
  63. getPageContent();
  64.  
  65. tempPageP4(true);
  66.  
  67. include("PHP/dbCon/closedb.php");
  68. ?>
Jun 30 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Saul | last post by:
Hi all! I was wondering if a few of you might want to try out my new online game here... GEEKSLOTS! http://saulysw.servepics.com/Geekslots/frmSpin.aspx Which I wrote in ASP.NET. I have not...
1
by: Antimon | last post by:
Hi, I am working on a browser based space simulation game. I think about two different architectures but i cannot decide, First one is to use and rdbms to store persistent world data. But i...
1
by: Chu | last post by:
Hello All- I'm writing a game using asp.net (c#). The game is a browser-based Role Playing Game. I'm trying to determine the best way to design the game with scalability in mind. The Player...
11
tpgames
by: tpgames | last post by:
I've struck zero in finding a Link to a sudoku game that actually uses images for numbers, even images OF numbers. Yes, I'd prefer the game in JavaScript. Every site I've been too, (hundreds) uses...
3
by: =?Utf-8?B?cGNnYW1lcg==?= | last post by:
Is VB good for game development? Or is C# or some other language better? I'm a beginner programmer and would like to get into game development. I can't find any decent tutorials, so links would be...
4
by: COHENMARVIN | last post by:
Are there any good sources on video game programming in vb.net? Is "DirectX" a set of libraries for video game programmers? The reason I ask is that I'd like to convert a board game into a...
0
by: THE HARD | last post by:
The game is a game directly through the web site It is a game very impressive war There are responsible for the village there are alliances and soldiers, and can attack any village, and take all...
0
by: Madmartigan | last post by:
Hi I'm a newbie to C# and have been instructed to create a Hangman game in SharpDevelop. I don't want the answer to the full code, just some help along the way. I have included my code thus...
80
by: tech | last post by:
Hi, i have the following problem In file1.h namespace A { class Bar { void foo();
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.