Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:21:16+00:00 2026-06-03T03:21:16+00:00

First things first. I’m running CodeIgniter on a PHP/MySQL site. I’ve been tasked with

  • 0

First things first. I’m running CodeIgniter on a PHP/MySQL site.

I’ve been tasked with creating a “shell” application for a series of movies that a person can view for a training website that I’m building. The idea here is that a person would be able to log on to a page, click “Take Course” and have it log what time the course was taken. Then, when the person exits the page carrying the movie, I would be able to record what time the course was ended. This way I can compare the start and end times, and determine if the user had viewed most of the film in order to give the user credit. Well, the first part is easy. First, I’ve built a table in my database with the following fields:

  • intKey (intKey(10))
  • strHash (varchar(255))
  • dtBegan (datetime)
  • dtEnded (datetime)
  • varIpAddress (varchar(255))

I’ve put in a controller that does this:

$ip_address = $_SERVER['REMOTE_ADDR'];
$data['hash'] = md5(time() . "Proof of Concept!");
$this->db->query("INSERT INTO pocTime SET strHash = '" . $data['hash'] . "', dtBegan = now(), varIpAddress='$ip_address'");
$this->load->view('welcome_message',$data);

OK… easy enough, yes? I also know that when I am done, I want to launch a file that does this:

$ip_address = $_SERVER['REMOTE_ADDR'];
$this->db->query("UPDATE pocTime SET dtEnded = now() WHERE strHash = '" . $data['hash'] . "' AND varIpAddress='$ip_address'");

What I’m hoping to do is have a page that is called by the 1st block of code, and set a “trap” so to speak so that the 2nd block of code is run by some kind of “post back” if the rendered page is closed. Any suggestions? I know that I could put some sort of big “CLICK HERE TO END YOUR VIDEO” type button that would cover this, but I’m looking to run code on some form of exit from a page, because I don’t know what the user would do after viewing the video. Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:21:17+00:00Added an answer on June 3, 2026 at 3:21 am

    Simple but should work, using jQuery

    $(window).unload(function(){
        $.get("test.php?dim1=turn&dim2=off");
    });
    

    Using unload which jQuery documentation tells what triggers this:
    http://api.jquery.com/unload/

    Using get which jQuery documentation is here:
    http://api.jquery.com/get/

    Or you can use post as well

    $(window).unload(function(){ 
        $.post("test.php", { dim1: "turn", dim2: "off" } ); 
    });
    

    http://api.jquery.com/jQuery.post/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of the first things I like to do when I make a site
I'm a new guy in PHP OOP concepts. One of the first things that
So, first things first, I'm a student. I'm developing an application where other students
First things, first, I'm just starting with Android Application Development and would like to
First things first. This application is an ASP.NET application using windows authentication. Situation: The
I just started a new job and one of the first things I've been
First things first, I'm using: Java 1.7.0_02 MySQL 5.1.50 ZendServer CE (if that matters)
First things first: Server is an Apache running on Debian in a VMPlayer Host
One of the first things I learned in C++ was that #include <iostream> int
One if the first things I learned when I started with C# was the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.