Question

Hi , I am trying to make a rundown clock using sessions, with adding the number...

Hi , I am trying to make a rundown clock using sessions, with adding the number of visits feature using cookies. My code doesn't work. Could I get any help?
My code is below.

<?php
   session_start();
   ?>
<!DOCTYPE html>
<html>
   <head>
       <meta charset="UTF-8">
       <title>Cookie Exercise</title>
   </head>
   <body>
       <?php
       if (!isset($_SESSION["numOfVisits"])) {
       $_SESSION['countdown'] = 60;
       $_SESSION['startTime'] = time();
       setcookie("session","cookie", time() + 60);
   }
   $now = time();
   $cLength = $now - $_SESSION['startTime'];
   $timeRemain = abs($_SESSION['countdown'] - $cLength);
   $_COOKIE["numOfVisits"]=1;
   $_COOKIE['count']=$_COOKIE["numOfVisits"]++;
   ?>
       <p>There are <?php echo $timeRemain ?> seconds remaining. </p></br>
       <p>Page visit counter: <?php echo $_COOKIE['count']; ?> </p>
       <p> <?php if ($timeRemain<1) { ?> The cookies have been deleted! </p> <?php } ?> </p>
      
   </body>
</html>

Thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I'm attaching a solution for you, whether I don't know it will solve your problem , but it's working fine for me. First of all I cleared the solution for the problem you gave for me. Whatever I understand I put in the code here. Don't mine if it not reaches your think.

case1: in the particular session time of 60 seconds, it'll return how many times a user visits the page in that 60 seconds only.

case2: And if you want to count continuously irrespective of the session time you have to add the 2 lines in this code.

I'll show you how to do this.

solution.php

<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cookie Exercise</title>
</head>
<body>
<?php
if (!isset($_COOKIE["session"])) {
$_SESSION['countdown'] = 60;
$_SESSION['startTime'] = time();
setcookie("session","cookie", time() + 6);

// if(!isset($_COOKIE["visits"])){
$_COOKIE['visits'] = 1;
setcookie("visits",1, time()+36000);
// }
}
$now = time();
$cLength = $now - $_SESSION['startTime'];
$timeRemain = abs($_SESSION['countdown'] - $cLength);

setcookie("visits",$_COOKIE["visits"]+1, time()+60);

?>
<p>There are <?php echo $timeRemain ?> seconds remaining. </p></br>
<p>Page visit counter: <?php echo $_COOKIE['visits']; ?> </p>
<p> <?php if ($timeRemain<1) { ?> The cookies have been deleted! </p> <?php } ?> </p>

for the second case un-comment the 2 lines there.

please thumbs-up.

Thank you, if you have any doubts please comment in this question.

Add a comment
Know the answer?
Add Answer to:
Hi , I am trying to make a rundown clock using sessions, with adding the number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I was wondering if someone could help me with this PHP and HTML problem. Basically,...

    Hello, I was wondering if someone could help me with this PHP and HTML problem. Basically, there is code for a multiplication table and i need to change it to support the following. Make the page background (not table background) to change among three colors of your choice. Use the drop-down list to specify the size of the multiplication table to be 8, 10, 12, and 14 Put the multipliers in the first column and the multiplicand on the first...

  • Hey I am having an issue with my HTML5 document. Everything is working fine except that...

    Hey I am having an issue with my HTML5 document. Everything is working fine except that I am not sure how to make my <h1> Objective </h1> to align towards the left. I have tried for instance <p align = "Left"> <h1> <strong>Objective </strong> </h1> </p> Any help would be great. Thanks <!DOCTYPE html> <html> <!-- Do I need to use <head> right here? I tried it without head or urf-8 and it worked--> <!-- I'm still a bit confused...

  • In this exercise, you’ll modify the Future Value Calculator application to include a header and footer....

    In this exercise, you’ll modify the Future Value Calculator application to include a header and footer. Review the project Open the header.jsp file and note that it contains the code necessary for the start of an HTML page including the opening html, head, and body tags, the title for the web page, and a link including the CSS file. Open the footer.jsp file and note that includes a copyright notice and the closing body and html tags. Modify the code...

  • I am having an issue. When i press submit to test the code, it goes to...

    I am having an issue. When i press submit to test the code, it goes to a blank screen. Please, will some one assist me? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sign Guest Book</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (empty($_POST['?rst_name']) || empty($_POST['last_name']))     echo "<p>You must enter your ?rst and last name! Click your browser's Back button to return to the Guest Book form.</p>"; else {     $DBConnect = @mysql_connect("localhost", "root", "");    ...

  • PHP code that is given : <?php // Here is where your preprocessing code goes //...

    PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...

  • PHP - Use of classes This is a further development of the previous task, the participant...

    PHP - Use of classes This is a further development of the previous task, the participant registration. You must use the following Participant class. <?php class Deltaker { private $etterNavn; private $forNavn; private $fAar; function __construct(string $fornavn, string $etternavn, string $aar) { $this->forNavn = $fornavn; $this->etterNavn = $etternavn; $this->fAar = $aar; } function hentEtterNavn() : string { return $this->etterNavn; } function hentForNavn() : string { return $this->forNavn; } function hentFAar() : string{ return $this->fAar; } //Setters function settForNavn(string $fornavn) {...

  • Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an...

    Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an alert if the value of my selection is "0". I will be using this for a validation form assignement. So if the user leaves the selection on the default "0" value I can prompt the user to pick a valid option which would be 1+. Not sure how to access this value. Example code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Form Validation</title>...

  • I am trying to create a slide show using JavaScript. This is what I have so...

    I am trying to create a slide show using JavaScript. This is what I have so far: HTML: <!DOCTYPE html> <html lang="en"> <head>    <meta charset="utf-8"> <title>Slide Show</title> <link rel="stylesheet" href="main.css"> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="slide_show.js"></script> </head> <body> <section> <h1>Fishing Slide Show</h1> <ul id="image_list"> <li><a href="images/casting1.jpg" title="Casting on the Upper Kings"></a></li> <li><a href="images/casting2.jpg" title="Casting on the Lower Kings"></a></li> <li><a href="images/catchrelease.jpg" title="Catch and Release on the Big Horn"></a></li> <li><a href="images/fish.jpg" title="Catching on the South Fork"></a></li> <li><a href="images/lures.jpg" title="The Lures for Catching"></a></li> </ul>...

  • <!-- DOCTYPE declaration --> <!DOCTYPE html> <!-- HTML boilerplate code --> <html lang="en">    <!-- head...

    <!-- DOCTYPE declaration --> <!DOCTYPE html> <!-- HTML boilerplate code --> <html lang="en">    <!-- head tag -->    <head>                 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Personal Webpage</title>    </head>    <!-- body tag -->     <body>             <style>        .sidenav {            height: 100%;             width: 160px;            position: fixed;            z-index: 1;             top: 0;            left: 0;           ...

  • 1. Predict the Result.Draw and write a brief description of the Web page that will becreated...

    1. Predict the Result.Draw and write a brief description of the Web page that will becreated with the following XHTML code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>CircleSoft Designs</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">body { background-color: #FFFFCC;color: #330000;font-family Arial,Helvetica,sans-serif; }.content { width: 750px; }</style></head>Apply Your Knowledge<body><div class="content"><h1>CircleSoft Design</h1><div><strong>CircleSoft Designs will </strong><ul><li>work with you to create a Web presence that fits yourcompany</li><li>listen to you and answer your questions</li><li>utilize the most appropriate technology for your sites:JavaScript, Java, PHP, databases,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT