Validate Your WordPress AMP Site

You have already enabled the AMP in WordPress website. then you need to validate your WordPress site to see the AMP validation errors and warnings. I will let you know how to validate your WordPress AMP site step by step with screenshot.
Fortunately, there are several solutions for testing your AMP URLs. Pick a couple of key pages and test the AMP versions using one of the methods below.

1: AMP Test

Drop your URL in here and click “Run Test” then note the outcome.



2: AMP Validator

Paste the AMP URL in the URL field and click Validate, This tool will highlight any errors and flag them in the HTML.


Alternately you can also use the  AMP Validator Chrome extension.


  


Image Transparency / CSS Opacity.


The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent. The opacity property is often used together with the :hover selector to change the opacity on mouse-over.


img {
  opacity: 0.5;
  filter: alpha(opacity=50); /* For IE8 and earlier */
}
img:hover {
  opacity: 1.0;
  filter: alpha(opacity=100); /* For IE8 and earlier */
}

How to Create CAPTCHA validation in PHP

In this post, I cover the PHP code for creating captcha code to be stored in a session variable. I start the session to store the captcha which is dynamically created using the PHP rand() function. I have created an image target layer and write the random code. This JPEG captcha image will be shown in the contact form. like this image.


Add Captcha into HTML Contact Form.

This 'demo.php' file shows the HTML contact form with the CAPTCHA code.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Captcha</title>
<link href="./css/style.css" rel="stylesheet">
<script type='text/javascript'>
function refreshCaptcha(){
	var img = document.images['captchaimg'];
	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</head>
<body>
<div id="frame0">
  <h1>PHP Captcha Demo</h1>
</div>
<br>

<form action="" method="post" name="form1" id="form1" >
  <table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
    <?php if(isset($msg)){?>
    <tr>
      <td colspan="2" align="center" valign="top"><?php echo $msg;?></td>
    </tr>
    <?php } ?>
    <tr>
      <td align="right" valign="top"> Validation code:</td>
      <td><img src="captcha.php?rand=<?php echo rand();?>" id='captchaimg'><br>
        <label for='message'>Enter the code above here :</label>
        <br>
        <input id="captcha_code" name="captcha_code" type="text">
        <br>
        Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh.</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="Submit" type="submit" onclick="return validate();" value="Submit" class="button1"></td>
    </tr>
  </table>
</form>
</body>
</html>


Compare Captcha Code

On form submit, we should verify the captcha code, by comparing it with the corresponding $_SESSION variable. If match found, then, the user is recognized as human and the user information will be processed in the PHP file. Otherwise, Captcha validation error message will be displayed to the user. The code for validating the captcha is.


session_start();
if(isset($_POST['Submit'])){
	// code for check server side validation
	if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0){  
		$msg="The Validation code does not match!";// Captcha verification is incorrect.		
	}else{// Captcha verification is Correct. Final Code Execute here!		
		$msg="The Validation code has been matched.";		
	}
}


PHP code to Joint Function 

This 'captcha.php' file Joint function.

session_start();
	include("phptextClass.php");	
	
	/*create class object*/
	$phptextObj = new phptextClass();	
	/*phptext function to genrate image with text*/
	$phptextObj->phpcaptcha('#162453','#fff',120,40,10,25);


PHP code to Create CAPTCHA

This 'phptextClass.php' file create captcha cade.

class phptextClass
{	
	public function phptext($text,$textColor,$backgroundColor='',$fontSize,$imgWidth,$imgHeight,$dir,$fileName)
	{
		/* settings */
		$font = './calibri.ttf';/*define font*/
		$textColor=$this->hexToRGB($textColor);	
		
		$im = imagecreatetruecolor($imgWidth, $imgHeight);	
		$textColor = imagecolorallocate($im, $textColor['r'],$textColor['g'],$textColor['b']);	
		
		if($backgroundColor==''){/*select random color*/
			$colorCode=array('#56aad8', '#61c4a8', '#d3ab92');
			$backgroundColor = $this->hexToRGB($colorCode[rand(0, count($colorCode)-1)]);
			$backgroundColor = imagecolorallocate($im, $backgroundColor['r'],$backgroundColor['g'],$backgroundColor['b']);
		}else{/*select background color as provided*/
			$backgroundColor = $this->hexToRGB($backgroundColor);
			$backgroundColor = imagecolorallocate($im, $backgroundColor['r'],$backgroundColor['g'],$backgroundColor['b']);
		}
		
		imagefill($im,0,0,$backgroundColor);	
		list($x, $y) = $this->ImageTTFCenter($im, $text, $font, $fontSize);	
		imagettftext($im, $fontSize, 0, $x, $y, $textColor, $font, $text);
		if(imagejpeg($im,$dir.$fileName,90)){/*save image as JPG*/
			return json_encode(array('status'=>TRUE,'image'=>$dir.$fileName));
		imagedestroy($im);	
		}
	}	
	
	public function phpcaptcha($textColor,$backgroundColor,$imgWidth,$imgHeight,$noiceLines=0,$noiceDots=0,$noiceColor='#162453')
	{	
		/* Settings */
		$text=$this->random();
		$font = './font/monofont.ttf';/* font */
		$textColor=$this->hexToRGB($textColor);	
		$fontSize = $imgHeight * 0.75;
		
		$im = imagecreatetruecolor($imgWidth, $imgHeight);	
		$textColor = imagecolorallocate($im, $textColor['r'],$textColor['g'],$textColor['b']);			
		
		$backgroundColor = $this->hexToRGB($backgroundColor);
		$backgroundColor = imagecolorallocate($im, $backgroundColor['r'],$backgroundColor['g'],$backgroundColor['b']);
				
		/* generating lines randomly in background of image */
		if($noiceLines>0){
		$noiceColor=$this->hexToRGB($noiceColor);	
		$noiceColor = imagecolorallocate($im, $noiceColor['r'],$noiceColor['g'],$noiceColor['b']);
		for( $i=0; $i<$noiceLines; $i++ ) {				
			imageline($im, mt_rand(0,$imgWidth), mt_rand(0,$imgHeight),
			mt_rand(0,$imgWidth), mt_rand(0,$imgHeight), $noiceColor);
		}}				
				
		if($noiceDots>0){/* generating the dots randomly in background */
		for( $i=0; $i<$noiceDots; $i++ ) {
			imagefilledellipse($im, mt_rand(0,$imgWidth),
			mt_rand(0,$imgHeight), 3, 3, $textColor);
		}}		
		
		imagefill($im,0,0,$backgroundColor);	
		list($x, $y) = $this->ImageTTFCenter($im, $text, $font, $fontSize);	
		imagettftext($im, $fontSize, 0, $x, $y, $textColor, $font, $text);		

		imagejpeg($im,NULL,90);/* Showing image */
		header('Content-Type: image/jpeg');/* defining the image type to be shown in browser widow */
		imagedestroy($im);/* Destroying image instance */
		if(isset($_SESSION)){
			$_SESSION['captcha_code'] = $text;/* set random text in session for captcha validation*/
		}
	}
	
	/*for random string*/
	protected function random($characters=6,$letters = '23456789bcdfghjkmnpqrstvwxyz'){
		$str='';
		for ($i=0; $i<$characters; $i++) { 
			$str .= substr($letters, mt_rand(0, strlen($letters)-1), 1);
		}
		return $str;
	}	
	
	/*function to convert hex value to rgb array*/
	protected function hexToRGB($colour)
	{
			if ( $colour[0] == '#' ) {
					$colour = substr( $colour, 1 );
			}
			if ( strlen( $colour ) == 6 ) {
					list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
			} elseif ( strlen( $colour ) == 3 ) {
					list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
			} else {
					return false;
			}
			$r = hexdec( $r );
			$g = hexdec( $g );
			$b = hexdec( $b );
			return array( 'r' => $r, 'g' => $g, 'b' => $b );
	}		
		
	/*function to get center position on image*/
	protected function ImageTTFCenter($image, $text, $font, $size, $angle = 8) 
	{
		$xi = imagesx($image);
		$yi = imagesy($image);
		$box = imagettfbbox($size, $angle, $font, $text);
		$xr = abs(max($box[2], $box[4]));
		$yr = abs(max($box[5], $box[7]));
		$x = intval(($xi - $xr) / 2);
		$y = intval(($yi + $yr) / 2);
		return array($x, $y);	
	}
}


PHP Captcha Download File

Click to download core php captcha all file download now... 

Binary tree - how to count all left and right side nested child.

Hello Friends,
It is very easy before you create a table in your database.
Example: Table name 'tree_class' and create class name.
  1. snc
  2. Prenticeclass
  3 chillclasslt
  4. Chillclassaright
This screenshot of the database.



You create a function that counts all the children on the left and right side like this.

$memid="95000";   // Your Parent id
function getTotalLeg($memid,$leg){ 
      global $conn;
     $sql="select child_class from tree_class where parent_id='".$memid."' and position='".$leg."'";
      $res=mysqli_query($conn,$sql);
      $row=mysqli_fetch_array($res);
      global $total;
       $total=$total+mysqli_num_rows($res);
         if($row['child_class']!=''){
           getTotalLeg ($row['child_class'],'L');
           getTotalLeg ($row['child_class'],'R');
          } 
          return $total;      
        }      

     $total=0; 
    $left=getTotalLeg($memid,"L");    
    echo $total.""; 
     $total=0;
    $right=getTotalLeg($memid,"R");  
    echo $total; 

Your result will come like this.


How Do I Open a Link in a New Tab But Stay on the Same Page Using HTML?

When building a website, sometimes you want a link to open in a new tab while keeping the user on the same page. This is especially useful when linking to external websites, documents, or resources, so visitors don’t lose their current browsing session.

In this post, we’ll show you how to achieve this using simple HTML and JavaScript.

1. Using target="_blank":-
The simplest way to open a link in a new tab is by using the target="_blank" attribute in your <a> tag.

<a href="http://example.com/" target="_blank">Open New Link</a> 

2. Using JavaScript window.open() :-

To open a link in a new tab while ensuring the user stays on the same page, you can use JavaScript’s window.open() method along with an onclick event.

Here’s the example code:

<a href="http://example.com/" target="_blank" onclick="window.open('http://example.com/'); return false;">Open New Link</a>

3. Explanation of Code:-

  1. href="http://example.com/" → Provides the link destination. 
    target="_blank" → Ensures the link opens in a new tab.
  2. onclick="window.open(...)" → Uses JavaScript to open the link in a new tab.
  3. return false; → Prevents the default behavior of navigating away from the current page. 

So, when the user clicks the link, the new page opens in a separate tab, but the current page remains open as it is.

4. Final Example 
Here’s a complete working example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Open Link in New Tab</title>
</head>
<body>
  <p>Click the link below to open it in a new tab without leaving this page:</p>
  <a href="http://example.com/" target="_blank" onclick="window.open('http://example.com/'); return false;">Open New Link</a>
</body>
</html>

 


 

 

Python in AI: Getting Started with TensorFlow & PyTorch

  Artificial Intelligence (AI) is no longer just a buzzword. It powers recommendation systems, chatbots, self-driving cars, and more. At the...