Hi I am a PHP noob and I have been working on this PHP quiz application for my college project.
I have a database of questions and a PHP view page which will load a question from the database and when the user clicks the submit button.
It will then submit the form; on the server side it first stores the id of this question in the session so repetition of questions does not occur, check the answer of the question, and depending upon whether the response was correct or incorrect, an appropriate message will be transferred to the client side along with the current score and other details.
What I want now is a clock-like functionality which will automatically do something should the user run out of time.
Can anyone help me with that?
You may need to look for using setTimeout in javascript which runs the clock in client-side. Also you need to take care of tracking the starttime of the test in PHP $_SESSION and verify the submission in server-side.
Related
I'm programming a quiz and I've got a (hopefully) small problem:
I get the questions and their answers from a database and then I display it using a html form. By clicking on an answer the page gets reloaded, the chosen answer gets saved in the database and the form with the same question and answers gets displayed again - but with the difference, that the correct answer is highlighted in green and the buttons are disabled (in order to prevent users from clicking another time).
All this happens with all questions.
What I now want is to do exactly the same but without having to reload the page that often. I'd like to mark (highlight in green) the correct answer as soon as the user has chosen an answer by having clicked on a button or as soon as 10 seconds have passed.
I think of using Ajax in order to manage this but I have to pass the variables to the php script and therefore it would be easy for users to just look at the source code and get the correct answer, wouldn't it be?
Is there another opportunity of doing so, which is also secure (so that cheating isn't that easy)?
You can reload certain parts of your form using AJAX, as for security, you can just send the users input to the server and do all your processing in php file, so there is no way to see which answer is correct in case if anyone would attemt to cheat.
Thank you for your answers, #K.I and #DarkBee, I think I've got a solution - I'll realize it using AJAX. The script with which ajax is communicating increases a session var. If the session var doesn't fit to another session var which gets increased by reloading the question page, I'll disqualify the user. I think that should do, anyway, I'll give it a try ;)
I'm making a simple mobile web app where users should be able to login/authenticate to sign up for private events.
I love the way JQuery mobile looks and feels, but want PHP to do everything in the backend: Handle form processing, talk to the DB and so on.
I currently have no authentication, but want to add that.
Wrapping the current solution in Phonegap actually worked, but I suspect the authentication/session handling is going to crash with that.
My hope is that I can exchange data with a PHP script when:
- the form loads (to check for PHP user session etc), and
- a "submit" button is clicked.
I covered the submit button part, and it works. Data is sent to, and returned from my PHP processing script to the JQuery front-end.
For handling the submit event, for some reason this code worked:
$(document).ready(function(){
as opposed to an onclick thing which didn't work.
This baffles me, as I read that document.ready is an event that occurs when the document has completed loading.
Q1: Could this have something to do with me using Jquery mobile sections (
Q2: What would be the correct JQuery event/trigger to use prior to loading, to control form "context"? (based on data from backend PHP).
Q3a: Is it a viable solution to rely on PHP sessions in such a case?
Q4: Also considering that I'd like to Phonegap it...will a PHP session be able to "see" the Jquery-based, phonegap-wrapped app like a client session just like if it was someone using a web-browser?
4b. When does a Phonegap app user session "end"? (When does the user have to log in again...).
I know similar questions have been raised several times, but please consider I'm a gullible idiot that knows too little to understand which case is similar enough to mine. There are some concepts here that I need to grasp before I can decide what to investigate and ask about :-)
Here's to tolerance and understanding! Cheers!
Eivind
You can store mobile id and users id in database with flag logged_in when they first logged in. Then again if user open that app, you can check the mobile id with the record in database whether user is exists or not and if exists then whats his/her status.
I've been designing a site that is used to collect data, but the person I'm designing for wants some form of redundancy just in case the window is closed or the system shuts down. Is there any way to take data that's been collected and write it to a MYSQL database if the user is disconnected for a certain amount of time, or if they shut the browser window/shut the system down without submitting the data?
The web is stateless and disconnected - so all data will (or rather: should be) persisted between page requests.
I assume you have a web-page generated by PHP that contains a lengthy data-entry form, and you want to save the data in that form in the event the user closes their browser window - the solution is to use a client-script that polls the server with the current data in the form, or at the very least hooks on to the window close event.
Actual implementation is a task left up to the OP.
This can't be done just with a pure HTML page - if the user doesn't submit the form, your server doesn't know what they've typed.
However, you could put some Javascript on the page that made an AJAX call every few seconds (or every few key-stokes or clicks). The idea would be for the JavaScript to invisibly submit the whole form to a PHP page which saved it into a sort of "holding area".
If the user then submitted the form, the holding area could be cleared out, but if they never did, then the data in the holding area would show you where they got to.
The most common techniques to partially prevent this szenario is that web apps work with a heartbeat-function which fires via javascript in a constant interval and sends a request to the server, p.e. to show that the user is still logged on - or, in your case, maybe to submit data already typed into form fields, too.
Think of it as an ajax-powered auto-save-function!
You have to add some javascript to your code for this, but the commonly used javascript libraries, like jquery or mootools, are well documented and offer alot of examples how to do something like this.
I am using a php application. Here many users can login at same time like a web site.
Here a want when a user is saving form , a pop up should automatically appear on the browser of another user. id of 2nd user will be mentioned in form , when 1st user is savinf the form.
Please any body give me any idea.At least what type of technique i should use and what type of technology is required.
Thanks !
Rakesh
The technology you need is AJAX.
You should write a javascript function that calls periodically your server (through XMLHttpRequest) for any event you want to notify to your user,and when you have a relevant answer, that same function should pop up the warning.
You'll probably want to start using jQuery, a wonderful Javascript library (that includes Ajax calls) that will save you a lot of time.
I am developing an online learning system (PHP, MySQL and Javascript). I would like to track what pages and how long each users spent on each page. Ideally, I would like to record this in a MySQL database. My question is 2 fold:
1. What kind of fields would I include in my db table to record multiple pages accessed?
2. Is this problem best approached by server side only or by using javascript ? e.g. server side: hidden form fields with a page id attached, page id is passed to db and recorded?or Javascript: record all actions in Javascript variables and somehow pass to db at end of session?
Really I am just looking for some high level guidance on an approach as opposed to code snippets.
GF
PHP isn't my normal language, but I would think about creating a module of code that can be called from the top of each of your scripts, that basically logs away "I served this page, with these form variables, at xxx ... ". To be more precise, I would record that in a table.
If you need to know when the user left your page, for a page on another site or perhaps shut down their browser for instance, then a purely server side solution isn't going to cut the mustard. In that event, you are going to have to start thinking about JavaScript, and intercepting events - such as the onUnload event...
Have a read here...
While I know of no solution that can track individual users out of the box (I'm sure there are some), I am pretty sure you could customize Piwik to do this. Piwik aims to be a self-hostable alternative to Google Analytics. It is open source and build on Zend Framework and MySql.
Piwik collects usage statistics through a JavaScript tracking code and a Webbug image for fallback. Basically, what you would need to do is pass the logged in user's user id to the tracking script and then write a plugin that knows how to handle this information.