29 September 2021

How to create quiz timer (Left time) in PHP?

Create quiz timer in PHP. 

<!DOCTYPE html>

<html lang="en">

<body>

<center>

<div class="time" id="navbar">Time left :<span id="timer"></span></div>

<button class="button" id="mybut" onclick="myFunction()">START QUIZ</button>

</center>

<div id="myDIV" style="padding: 10px 30px;">

<form action="result.php" method="post" id="form"> 


</form>

</div>

<script>

function myFunction() {

var x = document.getElementById("myDIV");

    var b = document.getElementById("mybut");

    var x = document.getElementById("myDIV");

if (x.style.display === "none") { 

b.style.visibility = 'hidden';

x.style.display = "block";

startTimer();

}

}

window.onload = function() {

  document.getElementById('myDIV').style.display = 'none';

};

</script>

<?php

$settime = 0 . ':' . 01 . ':' . 06;

?>

 <script type="text/javascript">

document.getElementById('timer').innerHTML = '<?php echo $settime; ?>';

  //06 + ":" + 00 ;

function startTimer() {

  var presentTime = document.getElementById('timer').innerHTML;

  var timeArray = presentTime.split(/[:]+/);

  var h = timeArray[0];

  var m = timeArray[1];

  var s = checkSecond((timeArray[2] - 1));

  if(s==59){

  m=m-1

   if(m==0 && h>0){

h=h-1

m=59

  } 

  }

    document.getElementById('timer').innerHTML =

    h + ":" + m + ":" + s;

  if(h==0 && m==0 && s==0){

  //document.getElementById("form").submit();

  console.log('Time is Done.');

  if(s==0){

return true;

  }

  }

 setTimeout(startTimer, 1000);

}

function checkSecond(sec) {

  if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10

  if (sec < 0) {sec = "59"};

  return sec;

 // if(sec == 0 && m == 0){ alert('stop it')};

}

function checkmintue(min) {

  if (min < 10 && min >= 0) {min = "0" + min}; // add zero in front of numbers < 10

  if (min < 0) {min = "59"};

  return min;

 // if(min == 0 && h == 0){ alert('stop it')};

}

</script>

</body>

</html>

28 September 2021

How to create event time(Timmer) in PHP and Javascript?

Create event time(Timmer) in PHP and Javascript.


<?php 
/* date_default_timezone_set('Asia/Calcutta');
$timestamp = time(); */
//set hours according to the India time

$date = '2021-09-28';
$hour = '13';
$minutes = '14';
$seconds = '0';

?>
<div id="timer"></div>
<script>

//task: get timer details from the previous section and assign them to variables. 
//tip, these are associative arrays accessed as $myArray['data'] 

const countDownDate = <?php 


 echo strtotime("$date $hour:$minutes:$seconds" ) ?> * 1000;

let timeNow = <?php print(time()) ?> * 1000;

// Every second, the countdown will be updated.

let i = setInterval(function() {

 timeNow = timeNow + 1000;

// Calculate the time between now and the end of the countdown.  

let dist = countDownDate - timeNow;

// Calculate the number of days, hours, minutes, and seconds in days, hours, minutes, and seconds.

let numOfDays = Math.floor(dist / (1000 * 60 * 60 * 24));

let hr = Math.floor((dist % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

let min = Math.floor((dist % (1000 * 60 * 60)) / (1000 * 60));

let sec = Math.floor((dist % (1000 * 60)) / 1000);

// Put the result in an element with the id="timer" attribute.  

document.getElementById("timer").innerHTML = numOfDays + "d " + hr + "h " +

min + "m " + sec + "s ";

// When the countdown is over, type some text. 

if (dist < 0) {

clearInterval(i);

document.getElementById("timer").innerHTML = "TIMER EXPIRED";

}

}, 1000);

</script>

How to create quiz timer or time countdown in PHP and Javascript?

Create quiz timer or time countdown in PHP and Javascript.


 <!DOCTYPE html>

<html lang="en">

<body>

<center>

<div class="time" id="navbar">Time left :<span id="timer"></span></div>

<button class="button" id="mybut" onclick="myFunction()">START QUIZ</button>

</center>

<div id="myDIV" style="padding: 10px 30px;">

<form action="result.php" method="post" id="form"> 


</form>

</div>

<script>

function myFunction() {

var x = document.getElementById("myDIV");

    var b = document.getElementById("mybut");

    var x = document.getElementById("myDIV");

if (x.style.display === "none") { 

b.style.visibility = 'hidden';

x.style.display = "block";

startTimer();

}

}

window.onload = function() {

  document.getElementById('myDIV').style.display = 'none';

};

</script>

<?php

$settime = 06 . ':' . 00;

?>

 <script type="text/javascript">

document.getElementById('timer').innerHTML = '<?php echo $settime; ?>';

  //06 + ":" + 00 ;

function startTimer() {

  var presentTime = document.getElementById('timer').innerHTML;

  var timeArray = presentTime.split(/[:]+/);

  var m = timeArray[0];

  var s = checkSecond((timeArray[1] - 1));

  if(s==59){m=m-1}

    document.getElementById('timer').innerHTML =

    m + ":" + s;

  if(m==0 && s==0){

  //document.getElementById("form").submit();

  console.log('Time is Done.');

  if(s==0){

return true;

  }

  }

 setTimeout(startTimer, 1000);

}

function checkSecond(sec) {

  if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10

  if (sec < 0) {sec = "59"};

  return sec;

  if(sec == 0 && m == 0){ alert('stop it')};

}

</script>


</body>

</html>

24 September 2021

How to play youtube video on website with youtube link in PHP?

YouTube video on website with youtube link in PHP.

<?php

$topic_youtube_link = 'https://www.youtube.com/embed/vLFi-ODflLI';

$ytarray=explode("/", $topic_youtube_link);

$ytendstring=end($ytarray);

$ytendarray=explode("?v=", $ytendstring);

$ytendstring=end($ytendarray);

$ytendarray=explode("&", $ytendstring);

$ytcode=$ytendarray[0];

?>

<ifr ame class="play-youtube" src="https://www.youtube.com/embed/<?php echo $ytcode; ?>"  title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

<?php

How to add custom meta value in edit order page in Woo-commerce in Wordpress?

Add custom meta value in edit order page in Woo-commerce in Wordpress? 


//===============add meta data on edit order page =========================
/**
 * @param $item_id
 * @param $item
 * @param $product   Product
 */
function wpcodekit_order_meta_customized_display( $item_id, $item, $product ) {
global $woocommerce, $post;
    /*
    *  The default key to "$all_meta_data" can be: _qty,_tax_class,_line_tax,_line_tax_data,_variation_id,_product_id,_line_subtotal, _line_total,_line_subtotal_tax
    */
    $all_meta_data = get_metadata( 'order_item', $item_id, "", "" );  
//print_r($product);
echo $product->get_id();
echo $order_id = $post->ID;
/* 
$order = new WC_Order($post->ID);
//to escape # from order id 
echo $order_id = trim(str_replace('#', '', $order->get_order_number())); */



    ?>
    <div class="order_data_column" style="width: 50%; padding: 0 5px;">
        <h4><?php _e( 'Customized Values' ); ?></h4>
        <?php
            echo '<p><span style="display:inline-block; width:100px;">' . __( "Item to show 01" ) . '</span><span>:&nbsp;' . "Value to show 01" . '</span></p>';
    ?>
     </div>
<?php
}


add_action( 'woocommerce_after_order_itemmeta', 'wpcodekit_order_meta_customized_display',10, 3 );

23 September 2021

How to upload file in selected folder in PHP in Wordpress?

Upload file in selected folder in PHP in Wordpress. 


   <?php

   //echo $folder =  get_stylesheet_directory_uri();

  // echo $_SERVER["DOCUMENT_ROOT"];

 extract($_POST);

 global $wpdb;

 if(isset($_POST['submit'])){

 

$filename = $_FILES["file"]["name"];

$ext = pathinfo($filename, PATHINFO_EXTENSION);

$encrypt_file= md5(str_replace(" ", "_", $filename).date("Y-m-d-h-i-s"));

$realpath = $encrypt_file.'.'.$ext;

   $tempname = $_FILES["file"]["tmp_name"];

   echo $folder =  $_SERVER["DOCUMENT_ROOT"]."/raising/wp-content/themes/twentytwenty-child/img/".$realpath;

   //echo $folder =  get_stylesheet_directory_uri()."/img/".$filename;

   move_uploaded_file($tempname,$folder);

   

 

 }


if(!empty($folder)){

?>

<img src="<?php echo get_stylesheet_directory_uri()."/img/".$realpath; ?>" width="400" height="400">

<?php

}

?>

<form action="" method="post" enctype="multipart/form-data" >

<input type="file" name="file" id="file" class="form-upl">

<input type="submit" name="submit" value="Submit">

</form>

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...