Jump to content

Fixed score


tecmeister

Recommended Posts

you could try using cookies...mmmmm....cookies.....(easier), or session variables(more secure).

 

For Cookie:

--

give each question page an id

 

on each question page add this to the VERY start of your page (before anything is sent to the browser)

<?php 
$cStr = @$_COOKIE['Cookiename']; 
if(preg_match("/^PageID/",$cStr) == 0){
   setcookie("Cookiename",$cStr.";PageID",time()+86400); 
}else{
   // Could use Header("Location: nextpage.php");exit(); to redirect if the user has already submitted this question.
}
?>

 

replace "Cookiename" with a name of your choice (MUST be same on ALL pages)

also replace "PageID" with a Unique String of Characters for each question page

_

Next Add a Check where you add the points to the score, something like:

<?php
if(preg_match("/^PageID/",$_COOKIE['Cookiename']) != 0){
   // Add or Subtract Player Score
}
?>

 

This way they can still view the page and continue if they accidentally hit the back button. (Assuming you did not use my suggestion for header() redirect)

=====

NOTE: I have not used preg_match and setcookie for a long time i hope this example works ;)

 

 

 

 

__________________________

OR with Session Variables:

 

you are familiar with sessions.

Same Theory, Add a unique ID to each page

 

<?php 
$sStr = @$_SESSION['PID_String']; 
if(preg_match("/^PageID/",$sStr) == 0){
   $_SESSION['PID_String'] .= ";PageID";
}else{
   // Could use Header("Location: nextpage.php");exit(); to redirect if the user has already submitted this question.
}
?>

replace "PageID" with a Unique String of Characters for each question page

_

Next Add a Check where you add the points to the score, something like:

<?php
if(preg_match("/^PageID/",$_SESSION['PID_String']) != 0){
   // Add or Subtract Player Score
}
?>

 

Unfortunately with this alone, all the user has to do is close the browser, of course the user would have to login again - then start again, so if your saving results to a username this should not be a problem.

 

You MAY want to check if $_SESSION['username'] exists (isset() function is handy for this), if it doesn't then redirect to the login/start page.

 

 

_______________________________

Good luck hope it helps

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.