Home Blog Page 23

swap two numbers without using a temporary variable …

124

C Program to swap two numbers without using third variable with programming examples for beginners and professionals covering concepts, control statements, c array, c pointers, c structures, union, c strings and more.

swap.c

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\n enter the value of a and b :");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("swapping of a=%d",a);
printf("swapping of b=%d",b);
getch();
}

 

How to hide extension of html and php file.?

52

welcome back to shortlearner.com , In this tutorial  we will see how to hide extension of files using .htaccess
before start learning first of all we should  know about .htaccess file
what is .htaccess

hide extension of url using htaccess
in a simple words we can say that the .htaccess is a configuration file for use on web servers running the
Apache Web Server software. When a .htaccess file is placed in a directory
which is in turn ‘loaded via the Apache Web Server’,
then the .htaccess file is detected and executed by the Apache Web Server software.

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Benefits of using .htaccess

  • Redirect the user to different page
  • Password protect a specific directory
  • Block users by IP
  • Preventing hot linking of your images
  • Rewrite URIs
  • Specify your own Error Documents

In this tutorial we make 3 php pages and hide there extensions using .htaccess file.
index.php

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Remove .php extension with .htaccess by http://mainvps.shortlearner.com/</title>
         
        
        
    </head>
<body>
 
<center>

<div id="menu">
<ul>
	<li><a href="index">home</a></li>
    <li><a href="login">login</a></li>
    <li><a href="signup">signup</a></li>
  
</ul>
</div>

<div id="body">

<h1>This is index.php page | see the url in addressbar</h1> <br />


</div>
</center>
 
</body>
</html>

Signup.php

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Remove .php extension with .htaccess by http://mainvps.shortlearner.com/</title>
         

        
    </head>
<body>
 
<center>

<div id="menu">
<ul>
	<li><a href="index">home</a></li>
    <li><a href="login">login</a></li>
    <li><a href="signup">signup</a></li>
   
</ul>
</div>

<div id="body">

<h1>This is signup.php page | see the url in addressbar</h1>

</div>
</center>
</body>
</html>

Login.php

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Remove .php extension with .htaccess by http://mainvps.shortlearner.com/</title>
         
        <link rel="stylesheet" href="style.css" type="text/css" />
        
    </head>
<body>
 
<center>

<div id="menu">
<ul>
	<li><a href="index">home</a></li>
    <li><a href="login">login</a></li>
    <li><a href="signup">signup</a></li>
   
</ul>
</div>

<div id="body">

<h1>This is login.php page | see the url in addressbar</h1><br />



</div>
</center>
</body>
</html>

Save below code with .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html


</IfModule>

 

Add Google reCAPTCHA On Registration form

909

In this post we will see how to add google reCaptcha in signup form.

Google has released the new reCAPTCHA. Using reCAPTCHA users can prove they are human without solving a CAPTCHA. They need just a single click to confirm they are not a robot. So, reCAPTCHA will protect your website from spam with better user experience. You can easily integrate Google reCAPTCHA in PHP script.
Now We have create a signup/ registration form with the new Google reCAPTCHA using PHP.The reCAPTCHA integration process is given below.

First of all we need reCAPTCHA API keys:
For adding reCAPTCHA to your website, you need to register your site and get reCAPTCHA API keys.
Register your site

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Register your site at Google just click on the below link – https://www.google.com/recaptcha/admin

after click on above link here you got 2 keys.
first is site key which is used for showing captecha on client site
and another is secret key which is used to check the captecha on server end.

Connection.php

in this page we make our database connection.

<?php

$con= mysqli_connect("localhost","root","password","db_name")
?>

index.php

In the index.php we make a signup form.

<!DOCTYPE html>
<html>
<head>
<title>Google Captcha Integration </title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
<form class="form-horizontal" method="post" action="signup.php">
                     <!-- Text input-->
<div class="form-group">
  
  <div class="col-md-6">
   <label class="col-md-4 control-label" for="textinput">Name</label>  
    <input id="textinput" name="name" type="text" placeholder="Enter your Name Here" class="form-control input-md">
     </div>
       <div class="col-md-6">
      <label class="col-md-4 control-label" for="textinput">Email</label>
  <input id="textinput" name="email" type="text" placeholder="email" class="form-control input-md">
	</div>
        <div class="col-md-6">
       <label class="col-md-4 control-label" for="textinput">Country</label>
      <input id="textinput" name="country" type="text" placeholder="Enter your country here..!!" class="form-control input-md">

	</div>
    <div class="col-md-6">
   <label class="col-md-4 control-label" for="textinput">Mobile</label>  
    <input id="textinput" name="mobile" type="text" placeholder="+9123465686522" class="form-control input-md">
     </div>
     

  <div class="col-md-12" style="margin-top: 20px;">

  </div>
   
  </div>

<br>
 <div class="g-recaptcha" data-sitekey="enter you secret key here.."></div>

<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label" for=""></label>
  <div class="col-md-4">
	  <input  type="submit" name="sub" class="btn btn-primary  btn-lg" style="width: 250px; background-color:#1a7dc6;">
  </div>
</div>

							  </form>
</body>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</html>

signup.php

<?php
if(isset($_POST["sub"]))
{
  $email;$comment;$captcha;
        if(isset($_POST['email'])){
          $email=$_POST['email'];
        }
if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<h2>Please check the the captcha form.</h2>';
          exit;
        }
        $secretKey = " enter your secret key here..";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
        if(intval($responseKeys["success"]) !== 1) {
          echo '<h2>123</h2>';
        } else {
          echo '<h2>.</h2>';
        }
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
require("connection.php");
 
// Check connection
if($con === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 
// Escape user inputs for security

$name = mysqli_real_escape_string($con, $_REQUEST['name']);
$email = mysqli_real_escape_string($con, $_REQUEST['email']);
$country = mysqli_real_escape_string($con, $_REQUEST['country']);
$mobile = mysqli_real_escape_string($con, $_REQUEST['mobile']);
 
// attempt insert query execution
$sql = "INSERT INTO subscriber (name,email,country,mobile) VALUES ('$name', '$email','$country','$mobile')";
if(mysqli_query($con, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
}
 
// close connection
mysqli_close($con);
}
?>

KEEP LEARNING

PHP Login Script With Remember me.

5241

welcome back to shortlearner.com , In this tutorial we will see how to make a login form with remember me feature. In this example we are using PHP cookies for preserving user login and password.
PHP Login Form
This code shows login form with PHP code to pre-populate user login and passsword. this form has a remember me check box. if it is set then the login details entered by the user will preserved for future login attempts.

login with remember me option in php

Generate PDF from MySQL Data using PHP.

594

In this tutorial I explains how to generate PDF from MySQL Data using PHP. You are going to see how to convert MySQL Data into PDF using FPDF library.
Before start learning first of all we should know about Fpdf.

What is Fpdf.?

The FPDF is awesome PHP class to generate PDF using PHP from MySQL/MySqli database.This is open source php library to generate pdf file using PHP.
Awesome Features of FPDF.

  • Choice of measure unit, page format and margins.
  • Page header and footer management.
  • Automatic page and line break with text justification
  • Image support (JPEG, PNG and GIF).
  • Colors
  • Links
  • TrueType, Type1 and encoding support
  • Page compression.