Friday, 8 November 2019

Redirect your https page to http page using .htaccess file

Some free hosting provider not support SSL. If some visitor try to visit https://yourdomain then show 

SSL not enable

You can redirect your https visitor to http using .htaccess file

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

 or 
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

or

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
    Redirect "https://www.example.com/" "http://www.example.com/"
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.com
    # ...
</VirtualHost>

Thursday, 31 October 2019

clear smarty cache automatically in prestashop

The script should work assuming you place the script in the root folder of your store

<?php

require(dirname(__FILE__).'/config/config.inc.php');

//change 'abc123' to any value you wish to use
$token = Tools::getValue('token');
if (!$token || $token != 'abc123')
     die();

Tools::clearSmartyCache();
Tools::clearXMLCache();
Media::clearCache();
PrestaShopAutoload::getInstance()->generateIndex();


Then create a new cronjob that would execute your php script at the interval you desire, and you can test this from a browser to ensure it works properly


Thursday, 12 September 2019

How to install NEW CentOS Web Panel

For CentOS Web Panel Installation :
Step 1 – Login to your Centos7 server as root
Step 2 – Install Centos web control panel ( CWP ) using command below

run following command as root  (it runs 10-20 minutes):

yum update

yum install wget 

cd /usr/local/src

wget http://centos-webpanel.com/cwp-latest

sh cwp-latest



Login
———————
go to CentOS WebPanel Admin GUI at http://SERVER_IP:2030/
Username: root
Password: your root password
Configuration of WebPanel
– Setup nameservers
– Setup shared ip
– Setup at least one hosting package
– Setup root email
& now you are ready to host domains…


change port 22 in Contents of File: /etc/csf/csf.conf for reduce hacking chance
After installation i try to login in phpmyadmin I got error  '#1045 Access denied for user 'root'@'localhost' (using password: YES)'
for this I solve using this method:
login winscp as root
etc/my.cnf    
add this 
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
skip-grant-tables


or 
login putty

mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Thursday, 5 September 2019

Using Putty SSH Client To Import Large MySQL Databases To PHPMyAdmin

In this tutorial i’ll show you how to use the Putty SSH client to import large MySql Databases from your public_html root directory to a New database in PhpMyAdmin.

  • Download Putty
  • Upload your My Sql database file to my sites public_html root directory
  • Create a new database using the MySql database wizard in cPanel
  • Enter a command line in Putty which imports the database to PhpMyAdmin
Once you have download Putty, Click the desktop shortcut and click run.
Next step is to enter your Hostname or I.P address and use port 22. If you are entering your hostname, leave out the http://www and simply enter yourdomain.com.
  • You can then enter your cPanel username and click enter
  • Then enter your password and click enter.
  • The final step is to enter the command line below
mysql -u database_user -p database_db < /home/username/public_html/database.sql
and click enter. (make sure to replace the path in blue & red with the correct address to your database. The filename for your SQL database file is in red. You’ll also need to replace the part in green with your new database username and password.
database_user = your database username
database_db = your db name
username = username ( hosting account username ) 
database.sql = database file name
after replace all details Enter 
now enter your database password and Enter
Wait now for uploading data in phpmyadmin
Make sure you have upload your database to the root( public_html) directory of your site as this is where it will be uploaded from to phpmyadmin.

Tuesday, 3 September 2019

Simple static style.css

Index.html
<!--- code start for index page -->

<html><head>
    <title>Test Style css</title>
    <LINK href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
    <div id ="wrapper">
    <div id ="header">
    <div id ="logo"></div></div>
    <div id ="navbar"></div>
    <div id ="container">
    <div id ="left-panel"></div>
    <div id ="right-section"></div>
    </div>
    <div style="clear:both"></div>
    <div id ="footer"></div>
    
    </div>
    

</body></html>

<!--- code end for index page -->

<!--- code start for style page -->


/**autor raj **/
*{padding:0; margin:0;}
#wrapper{padding:10px;}
#header{height:100px; background-color:#f1c233; padding:10px;}
#logo{width:150px; height:100px;background-color:#a20b32;}
#navbar{height:50px;background-color:#758209; margin-top:10px;}
#container{margin-top:10px;}
#container :: after{content: " "; display:block; clear:both;}
#left-panel{width:25%; height:600px; background-color:#eda150;float:left;}
#right-section{width:74%; height:600px;background-color:#bcc92b; float:right;}
#footer{height:100px;background-color:#79d17b; margin-top:10px;}

<!--- code end for index page -->

Simple responsive style.css

Index.html
<!--- code start for index page -->
<html><head>
    <title>Test Style css</title>
    <LINK href="style.css" rel="stylesheet" type="text/css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 
</head>
<body>
    <div id ="wrapper">
    <div id ="header"></div>
 
    <div id ="content">
    <div id ="left-panel">
        <div id ="navbar"></div>
        <div id ="news"></div>
    </div>
    <div id ="right-section"></div>
    </div>
    <div style="clear:both"></div>
    <div id ="footer"></div>
 
    </div>
 
</body></html>
<!--- code end for index page -->

<!--- code start for style page -->

/**autor raj **/
@media(min-width:1200px){
#wrapper{padding:10px;}
#header{background-color:#ff1a75; height:100px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;}
#content{margin-top:15px;}
#content :: after{content: " "; display:block; clear:both;}
#left-panel{
    width:20%;
    height:600px;
    float:left;}
#navbar{
    background-color:#ff1a75;
    height:400px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
#news{
    background-color:#ff1a75;
    height:200px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
margin-top:10px;
}
#right-section{
    background-color:#ff1a75;
    height:610px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
width:78.2%;
float:right;}
#footer{background-color:#ff1a75;
margin-top:10px;
height:100px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
    }
 
 
@media(min-width:992px) and (max-width:1199px){
    #wrapper{padding:10px;}
#header{background-color:#ff1a75; height:100px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;}
#content{margin-top:15px;}
#content :: after{content: " "; display:block; clear:both;}
#left-panel{
    width:20%;
    height:600px;
    float:left;}
#navbar{
    background-color:#ff1a75;
    height:400px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
#news{
    background-color:#ff1a75;
    height:200px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
margin-top:10px;
}
#right-section{
    background-color:#ff1a75;
    height:610px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
width:78.2%;
float:right;}
#footer{background-color:#ff1a75;
margin-top:10px;
height:100px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
}
@media(min-width:768px) and (max-width:991px){
    #wrapper{padding:10px;}
#header{background-color:#ff1a75; height:100px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;}
#content{display:table; width:100%; margin-top:15px;}
#left-panel :: after{content: " "; display:block; clear:both;}
#left-panel{
     display:table-footer-group;
 
    }
#navbar{
    background-color:#ff1a75;
    height:100px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
float:right;
width:78.2%;
}
#news{
    background-color:#ff1a75;
    height:100px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;

float:left;
width:20%;
}
#right-section{
    background-color:#ff1a75;
    height:610px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
margin-bottom:10px;
}
#footer{background-color:#ff1a75;
margin-top:10px;
height:100px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
}
@media(max-width:767px){
    #wrapper{padding:10px;}
#header{background-color:#ff1a75; height:100px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;}
#content{display:table; width:100%; margin-top:15px;}
#left-panel :: after{content: " "; display:block; clear:both;}
#left-panel{
     display:table-footer-group;
 
    }
#navbar{
    background-color:#ff1a75;
    height:100px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;

}
#news{
    background-color:#ff1a75;
    height:100px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
margin-top:10px;
}
#right-section{
    background-color:#ff1a75;
    height:610px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
margin-bottom:10px;
}
#footer{background-color:#ff1a75;
margin-top:10px;
height:100px;
    -moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
}

<!--- code end for index page -->

Monday, 26 August 2019

unzipper on brower

just create unzipper.php file in public_html folder and copy and paste code.
1.Upload zip file in your public_html folder
2. run your brower example http://yourdomainname.com/unzipper.php

<--- code start --->

<?php
/**
 * The Unzipper extracts .zip or .rar archives and .gz files on webservers.
 * It's handy if you do not have shell access. E.g. if you want to upload a lot
 * of files (php framework or image collection) as an archive to save time.
 * As of version 0.1.0 it also supports creating archives.
 *
 * @author  Andreas Tasch, at[tec], attec.at
 * @license GNU GPL v3
 * @package attec.toolbox
 * @version 0.1.1
 */
define('VERSION', '0.1.1');

$timestart = microtime(TRUE);
$GLOBALS['status'] = array();

$unzipper = new Unzipper;
if (isset($_POST['dounzip'])) {
  // Check if an archive was selected for unzipping.
  $archive = isset($_POST['zipfile']) ? strip_tags($_POST['zipfile']) : '';
  $destination = isset($_POST['extpath']) ? strip_tags($_POST['extpath']) : '';
  $unzipper->prepareExtraction($archive, $destination);
}

if (isset($_POST['dozip'])) {
  $zippath = !empty($_POST['zippath']) ? strip_tags($_POST['zippath']) : '.';
  // Resulting zipfile e.g. zipper--2016-07-23--11-55.zip.
  $zipfile = 'zipper-' . date("Y-m-d--H-i") . '.zip';
  Zipper::zipDir($zippath, $zipfile);
}

$timeend = microtime(TRUE);
$time = round($timeend - $timestart, 4);

/**
 * Class Unzipper
 */
class Unzipper {
  public $localdir = '.';
  public $zipfiles = array();

  public function __construct() {
    // Read directory and pick .zip, .rar and .gz files.
    if ($dh = opendir($this->localdir)) {
      while (($file = readdir($dh)) !== FALSE) {
        if (pathinfo($file, PATHINFO_EXTENSION) === 'zip'
          || pathinfo($file, PATHINFO_EXTENSION) === 'gz'
          || pathinfo($file, PATHINFO_EXTENSION) === 'rar'
        ) {
          $this->zipfiles[] = $file;
        }
      }
      closedir($dh);

      if (!empty($this->zipfiles)) {
        $GLOBALS['status'] = array('info' => '.zip or .gz or .rar files found, ready for extraction');
      }
      else {
        $GLOBALS['status'] = array('info' => 'No .zip or .gz or rar files found. So only zipping functionality available.');
      }
    }
  }

  /**
   * Prepare and check zipfile for extraction.
   *
   * @param string $archive
   *   The archive name including file extension. E.g. my_archive.zip.
   * @param string $destination
   *   The relative destination path where to extract files.
   */
  public function prepareExtraction($archive, $destination = '') {
    // Determine paths.
    if (empty($destination)) {
      $extpath = $this->localdir;
    }
    else {
      $extpath = $this->localdir . '/' . $destination;
      // Todo: move this to extraction function.
      if (!is_dir($extpath)) {
        mkdir($extpath);
      }
    }
    // Only local existing archives are allowed to be extracted.
    if (in_array($archive, $this->zipfiles)) {
      self::extract($archive, $extpath);
    }
  }

  /**
   * Checks file extension and calls suitable extractor functions.
   *
   * @param string $archive
   *   The archive name including file extension. E.g. my_archive.zip.
   * @param string $destination
   *   The relative destination path where to extract files.
   */
  public static function extract($archive, $destination) {
    $ext = pathinfo($archive, PATHINFO_EXTENSION);
    switch ($ext) {
      case 'zip':
        self::extractZipArchive($archive, $destination);
        break;
      case 'gz':
        self::extractGzipFile($archive, $destination);
        break;
      case 'rar':
        self::extractRarArchive($archive, $destination);
        break;
    }

  }

  /**
   * Decompress/extract a zip archive using ZipArchive.
   *
   * @param $archive
   * @param $destination
   */
  public static function extractZipArchive($archive, $destination) {
    // Check if webserver supports unzipping.
    if (!class_exists('ZipArchive')) {
      $GLOBALS['status'] = array('error' => 'Error: Your PHP version does not support unzip functionality.');
      return;
    }

    $zip = new ZipArchive;

    // Check if archive is readable.
    if ($zip->open($archive) === TRUE) {
      // Check if destination is writable
      if (is_writeable($destination . '/')) {
        $zip->extractTo($destination);
        $zip->close();
        $GLOBALS['status'] = array('success' => 'Files unzipped successfully');
      }
      else {
        $GLOBALS['status'] = array('error' => 'Error: Directory not writeable by webserver.');
      }
    }
    else {
      $GLOBALS['status'] = array('error' => 'Error: Cannot read .zip archive.');
    }
  }

  /**
   * Decompress a .gz File.
   *
   * @param string $archive
   *   The archive name including file extension. E.g. my_archive.zip.
   * @param string $destination
   *   The relative destination path where to extract files.
   */
  public static function extractGzipFile($archive, $destination) {
    // Check if zlib is enabled
    if (!function_exists('gzopen')) {
      $GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.');
      return;
    }

    $filename = pathinfo($archive, PATHINFO_FILENAME);
    $gzipped = gzopen($archive, "rb");
    $file = fopen($destination . '/' . $filename, "w");

    while ($string = gzread($gzipped, 4096)) {
      fwrite($file, $string, strlen($string));
    }
    gzclose($gzipped);
    fclose($file);

    // Check if file was extracted.
    if (file_exists($destination . '/' . $filename)) {
      $GLOBALS['status'] = array('success' => 'File unzipped successfully.');

      // If we had a tar.gz file, let's extract that tar file.
      if (pathinfo($destination . '/' . $filename, PATHINFO_EXTENSION) == 'tar') {
        $phar = new PharData($destination . '/' . $filename);
        if ($phar->extractTo($destination)) {
          $GLOBALS['status'] = array('success' => 'Extracted tar.gz archive successfully.');
          // Delete .tar.
          unlink($destination . '/' . $filename);
        }
      }
    }
    else {
      $GLOBALS['status'] = array('error' => 'Error unzipping file.');
    }

  }

  /**
   * Decompress/extract a Rar archive using RarArchive.
   *
   * @param string $archive
   *   The archive name including file extension. E.g. my_archive.zip.
   * @param string $destination
   *   The relative destination path where to extract files.
   */
  public static function extractRarArchive($archive, $destination) {
    // Check if webserver supports unzipping.
    if (!class_exists('RarArchive')) {
      $GLOBALS['status'] = array('error' => 'Error: Your PHP version does not support .rar archive functionality. <a class="info" href="http://php.net/manual/en/rar.installation.php" target="_blank">How to install RarArchive</a>');
      return;
    }
    // Check if archive is readable.
    if ($rar = RarArchive::open($archive)) {
      // Check if destination is writable
      if (is_writeable($destination . '/')) {
        $entries = $rar->getEntries();
        foreach ($entries as $entry) {
          $entry->extract($destination);
        }
        $rar->close();
        $GLOBALS['status'] = array('success' => 'Files extracted successfully.');
      }
      else {
        $GLOBALS['status'] = array('error' => 'Error: Directory not writeable by webserver.');
      }
    }
    else {
      $GLOBALS['status'] = array('error' => 'Error: Cannot read .rar archive.');
    }
  }

}

/**
 * Class Zipper
 *
 * Copied and slightly modified from http://at2.php.net/manual/en/class.ziparchive.php#110719
 * @author umbalaconmeogia
 */
class Zipper {
  /**
   * Add files and sub-directories in a folder to zip file.
   *
   * @param string $folder
   *   Path to folder that should be zipped.
   *
   * @param ZipArchive $zipFile
   *   Zipfile where files end up.
   *
   * @param int $exclusiveLength
   *   Number of text to be exclusived from the file path.
   */
  private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
    $handle = opendir($folder);

    while (FALSE !== $f = readdir($handle)) {
      // Check for local/parent path or zipping file itself and skip.
      if ($f != '.' && $f != '..' && $f != basename(__FILE__)) {
        $filePath = "$folder/$f";
        // Remove prefix from file path before add to zip.
        $localPath = substr($filePath, $exclusiveLength);

        if (is_file($filePath)) {
          $zipFile->addFile($filePath, $localPath);
        }
        elseif (is_dir($filePath)) {
          // Add sub-directory.
          $zipFile->addEmptyDir($localPath);
          self::folderToZip($filePath, $zipFile, $exclusiveLength);
        }
      }
    }
    closedir($handle);
  }

  /**
   * Zip a folder (including itself).
   *
   * Usage:
   *   Zipper::zipDir('path/to/sourceDir', 'path/to/out.zip');
   *
   * @param string $sourcePath
   *   Relative path of directory to be zipped.
   *
   * @param string $outZipPath
   *   Relative path of the resulting output zip file.
   */
  public static function zipDir($sourcePath, $outZipPath) {
    $pathInfo = pathinfo($sourcePath);
    $parentPath = $pathInfo['dirname'];
    $dirName = $pathInfo['basename'];

    $z = new ZipArchive();
    $z->open($outZipPath, ZipArchive::CREATE);
    $z->addEmptyDir($dirName);
    if ($sourcePath == $dirName) {
      self::folderToZip($sourcePath, $z, 0);
    }
    else {
      self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
    }
    $z->close();

    $GLOBALS['status'] = array('success' => 'Successfully created archive ' . $outZipPath);
  }
}
?>

<!DOCTYPE html>
<html>
<head>
  <title>File Unzipper + Zipper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <style type="text/css">
    <!--
    body {
      font-family: Arial, sans-serif;
      line-height: 150%;
    }

    label {
      display: block;
      margin-top: 20px;
    }

    fieldset {
      border: 0;
      background-color: #EEE;
      margin: 10px 0 10px 0;
    }

    .select {
      padding: 5px;
      font-size: 110%;
    }

    .status {
      margin: 0;
      margin-bottom: 20px;
      padding: 10px;
      font-size: 80%;
      background: #EEE;
      border: 1px dotted #DDD;
    }

    .status--ERROR {
      background-color: red;
      color: white;
      font-size: 120%;
    }

    .status--SUCCESS {
      background-color: green;
      font-weight: bold;
      color: white;
      font-size: 120%
    }

    .small {
      font-size: 0.7rem;
      font-weight: normal;
    }

    .version {
      font-size: 80%;
    }

    .form-field {
      border: 1px solid #AAA;
      padding: 8px;
      width: 280px;
    }

    .info {
      margin-top: 0;
      font-size: 80%;
      color: #777;
    }

    .submit {
      background-color: #378de5;
      border: 0;
      color: #ffffff;
      font-size: 15px;
      padding: 10px 24px;
      margin: 20px 0 20px 0;
      text-decoration: none;
    }

    .submit:hover {
      background-color: #2c6db2;
      cursor: pointer;
    }
    -->
  </style>
</head>
<body>
<p class="status status--<?php echo strtoupper(key($GLOBALS['status'])); ?>">
  Status: <?php echo reset($GLOBALS['status']); ?><br/>
  <span class="small">Processing Time: <?php echo $time; ?> seconds</span>
</p>
<form action="" method="POST">
  <fieldset>
    <h1>Archive Unzipper</h1>
    <label for="zipfile">Select .zip or .rar archive or .gz file you want to extract:</label>
    <select name="zipfile" size="1" class="select">
      <?php foreach ($unzipper->zipfiles as $zip) {
        echo "<option>$zip</option>";
      }
      ?>
    </select>
    <label for="extpath">Extraction path (optional):</label>
    <input type="text" name="extpath" class="form-field" />
    <p class="info">Enter extraction path without leading or trailing slashes (e.g. "mypath"). If left empty current directory will be used.</p>
    <input type="submit" name="dounzip" class="submit" value="Unzip Archive"/>
  </fieldset>

  <fieldset>
    <h1>Archive Zipper</h1>
    <label for="zippath">Path that should be zipped (optional):</label>
    <input type="text" name="zippath" class="form-field" />
    <p class="info">Enter path to be zipped without leading or trailing slashes (e.g. "zippath"). If left empty current directory will be used.</p>
    <input type="submit" name="dozip" class="submit" value="Zip Archive"/>
  </fieldset>
</form>
<p class="version">Unzipper version: <?php echo VERSION; ?></p>
</body>
</html>

<--- code end --->

Wednesday, 14 August 2019

PHP / MySQL Select Data And Split On Pages

Show mysql 100 data row in 20page in php

<?php
error_reporting(0);
$servername = "localhost";
$username = "demo_user ";     // MySQL user name
$password = "123456789 ";    // MySQL password
$dbname = "demo_demo ";   // MySQL database name
$datatable = "register "; // MySQL table name
$results_per_page = 5; // number of results per page

// Create connection
$con = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}
?>
<?php
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $results_per_page;
$sql = "SELECT * FROM ".$datatable." ORDER BY ID ASC LIMIT $start_from, ".$results_per_page;
$rs_result = $con->query($sql);
?>
<table border="1" cellpadding="4">
<tr>
    <td bgcolor="#CCCCCC"><strong>ID</strong></td>
    <td bgcolor="#CCCCCC"><strong>Name</strong></td><td bgcolor="#CCCCCC"><strong>Phone</strong></td></tr>
<?php
 while($row = $rs_result->fetch_assoc()) {
?>
            <tr>
            <td><? echo $row["ID"]; ?></td>
            <td><? echo $row["Name"]; ?></td>
            <td><? echo $row["PhoneNumber"]; ?></td>
            </tr>
<?php
};
?>
</table>



<?php
$sql = "SELECT COUNT(ID) AS total FROM ".$datatable;
$result = $con->query($sql);
$row = $result->fetch_assoc();
$total_pages = ceil($row["total"] / $results_per_page); // calculate total pages with results
 
for ($i=1; $i<=$total_pages; $i++) {  // print links for all pages
            echo "<a href='1.php?page=".$i."'";
            if ($i==$page)  echo " class='curPage'";
            echo ">".$i."</a> ";
};
?>

Thursday, 13 June 2019

Update data in mysql using php form

page name updatedata.php and Column in table : id , uid , upass , email.

 <!DOCTYPE html>
<html>
<head>
<title></title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="maindiv">
<div class="divA">
<div class="title">
<h2>Update Data </h2>
</div>
<div class="divB">
<div class="divD">
<p>Click On Menu</p>
<?php
$connection = mysql_connect("localhost", "root", "root password");
$db = mysql_select_db("db name", $connection);
if (isset($_GET['submit'])) {
$id = $_GET['did'];
$name = $_GET['dname'];
$email = $_GET['demail'];
$mobile = $_GET['dmobile'];

$query = mysql_query("update admin_log set
id='$id',uid='$name', email='$email', upass='$mobile' where id='$id'", $connection);
}
$query = mysql_query("select * from admin_log", $connection);
while ($row = mysql_fetch_array($query)) {
echo "<b><a href='updatedata.php?update={$row['id']}'>{$row['upass']}</a></b>";
echo "<br />";
}
?>
</div><?php
if (isset($_GET['update'])) {
$update = $_GET['update'];
$query1 = mysql_query("select * from admin_log where id=$update", $connection);
while ($row1 = mysql_fetch_array($query1)) {
echo "<form class='form' method='get'>";
echo "<h2>Update Form</h2>";
echo "<hr/>";
echo"<input class='input' type='hidden' name='did' value='{$row1['id']}' />";
echo "<br />";
echo "<label>" . "Name:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='dname' value='{$row1['uid']}' />";
echo "<br />";
echo "<label>" . "Email:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='demail' value='{$row1['email']}' />";
echo "<br />";
echo "<label>" . "Password:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='dmobile' value='{$row1['upass']}' />";


echo "</textarea>";
echo "<br />";
echo "<input class='submit' type='submit' name='submit' value='update' />";
echo "</form>";
}
}
if (isset($_GET['submit'])) {
echo '<div class="form" id="form3"><br><br><br><br><br><br>
<Span>Data Updated Successfuly......!!<br><br></span></div>';
}
?>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div><?php
mysql_close($connection);
?>
</body>
</html>

Thursday, 30 May 2019

Use Of MySQL Where Clause in php 7.3

The WHERE clause is used to extract only those records that fulfill a specified condition.
where clause is a part of select command . it is used to fetch data from a table . we basically use this clause to filter out our results. by using where clause we can select particular set of records based specified condition.

create database name dbname
table name :  empInfo
column : id , name , eid,mob

create connection.php page

<?php

$con=mysqli_connect("localhost","username","password","dbname") or die(mysqli_error());


?>

create index.php 

<?php 

include("connection.php");

?><!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">

<head>

<title>page title</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link href="style.css" rel="stylesheet" type="text/css" />



<style type="text/css">

<!--

.style4 { color: #0066CC;

font-weight: bold;

font-size: 16px;

}

-->

</style>

</head>

<body>

       

                      <?php

                      //select values from empInfo table where column=value

                     $data="SELECT * FROM empInfo where emp_id='devesh@gmail.com'";
$val=mysqli_query($con,$data);
echo "<table border='1'>";
echo "<tr><th>Emp_id</th><th>Name</th><th>Email</th><th>Mobile</th></tr>";

while(list($id,$name,$eid,$mob) =  mysqli_fetch_array($val))
{
echo "<tr>";
echo "<td>".$id."</td>";
echo "<td>".$name."</td>";
echo "<td>".$eid."</td>";
echo "<td>".$mob."</td>";
echo "</tr>";
}
echo "</table>";
 ?>

                          

                  <?php //}?>

              
</body>

</html>



Redirect http to https using .htaccess

Redirect your http page to https page using .htaccess file
create .htaccess file in your root folder and paste given code. Change red text to your domain name

<---- start code here ---->

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sakhihosting\.in [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sakhihosting.in/$1 [R=301,L]


<---- end code here ---->

Redirect Specified Folder

If you want to force SSL on a specific folder, insert the code below into a .htaccess file placed in that specific folder:
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R=301,L]


Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folderwith your actual domain name and folder you want to force the SSL on.

Sunday, 12 May 2019

CoinPayments.net Payments Module for BoxBilling

CoinPayments.net Payments Module for BoxBilling
This module is modified from the PayPal module that comes with BoxBilling.

1. Upload the bb-library folder into your BoxBilling root directory.
2. In your BoxBilling admin page, go to Configuration, Payment gateways, New payment gateway and click the Install button to the right of CoinPayments.
3. Click the Edit Settings button in the Payment Gateways list to the right of CoinPayments.
4. Optionally enter a debug email address to receive IPN errors (recommended during testing).
5. Select "Yes" next to "Enabled:" and "Allow one time payments:".
6. Select "No" next to "Enable test mode:".
7. Click "Update" to save your settings.

And you should be all set.


<------------ Code Start --------------->
<?php
/**
 * CoinPayments.net Payment Gateway for BoxBilling
 * Based on the original PayPal module
 *
 * BoxBilling
 *
 * LICENSE
 *
 * This source file is subject to the license that is bundled
 * with this package in the file LICENSE.txt
 * It is also available through the world-wide-web at this URL:
 * http://www.boxbilling.com/LICENSE.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@boxbilling.com so we can send you a copy immediately.
 *
 * @copyright Copyright (c) 2010-2012 BoxBilling (http://www.boxbilling.com)
 * @license   http://www.boxbilling.com/LICENSE.txt
 * @version   $Id$
 */
class Payment_Adapter_CoinPayments
{
    private $config = array();
    private $error_msg = '';
   
    public function __construct($config)
    {
        $this->config = $config;
       
        if(!$this->config['merchant_id']) {
            throw new Exception('Payment gateway "CoinPayments" is not configured properly. Please update configuration parameter "CoinPayments.net Merchant ID" at "Configuration -> Payments".');
        }
       
        if(!$this->config['ipn_secret']) {
            throw new Exception('Payment gateway "CoinPayments" is not configured properly. Please update configuration parameter "CoinPayments.net IPN Secret" at "Configuration -> Payments".');
        }
       
        if($this->config['test_mode']) {
            throw new Exception('Payment gateway "CoinPayments" does not support Test Mode. You can enable the Litecoin Testnet for testing transactions however.');
        }
    }

    public static function getConfig()
    {
        return array(
            'supports_one_time_payments'   =>  true,
            'supports_subscriptions'     =>  false,
            'description'     =>  'Enter your CoinPayments.net Merchant ID and IPN Secret to start accepting payments by CoinPayments.',
            'form'  => array(
                'merchant_id' => array('text', array(
                            'label' => 'CoinPayments.net Merchant ID',
                            'validators'=>array(),
                    ),
                 ),
                'ipn_secret' => array('text', array(
                            'label' => 'CoinPayments.net IPN Secret',
                            'validators'=>array(),
                    ),
                 ),
                'debug_email' => array('text', array(
                            'label' => 'Debug Email (will receive copies of all IPN errors)',
                            'validators'=>array('EmailAddress'),
                    ),
                 ),
            ),
        );
    }

    public function getHtml($api_admin, $invoice_id, $subscription)
    {
        $invoice = $api_admin->invoice_get(array('id'=>$invoice_id));
        $buyer = $invoice['buyer'];
       
        $p = array(
            ':id'=>sprintf('%05s', $invoice['nr']),
            ':serie'=>$invoice['serie'],
            ':title'=>$invoice['lines'][0]['title']
        );
        $title = __('Payment for invoice :serie:id [:title]', $p);
        $number = $invoice['nr'];
       
        if($subscription) {
            //we don't support recurring subs, but we'll at least do the first payment
            $subs = $invoice['subscription'];
           
            $data = array();
            $data['cmd']                = '_pay';
            $data['reset']              = 1;
            $data['merchant']           = $this->config['merchant_id'];
            $data['item_name']          = $title;
            $data['item_number']        = $number;
            $data['want_shipping']      = 1;
            $data['allow_extra']        = 0; // Do not prompt payers to include a note with their payments. Allowable values for Subscribe buttons:
            $data['currency']           = $invoice['currency'];
            $data['amountf']            = $this->moneyFormat($invoice['total'], $invoice['currency']); // Regular subscription price.
            $data['success_url']        = $this->config['return_url'];
            $data['cancel_url']         = $this->config['cancel_url'];
            $data['ipn_url']            = $this->config['notify_url'];
            $data['invoice']            = $invoice['id'];

            //client data
            $data['address1'] = $buyer['address'];
            $data['city'] = $buyer['city'];
            $data['email'] = $buyer['email'];
            $data['first_name'] = $buyer['first_name'];
            $data['last_name'] = $buyer['last_name'];
            $data['zip'] = $buyer['zip'];
            $data['state'] = $buyer['state'];           
        } else {
            $data = array();
            $data['cmd']                = '_pay';
            $data['reset']              = 1;
            $data['merchant']           = $this->config['merchant_id'];
            $data['item_name']          = $title;
            $data['item_number']        = $number;
            $data['want_shipping']      = 1;
            $data['allow_extra']        = 0; // Do not prompt payers to include a note with their payments. Allowable values for Subscribe buttons:
            $data['currency']           = $invoice['currency'];
            $data['amountf']            = $this->moneyFormat($invoice['total'], $invoice['currency']);
            $data['taxf']               = $this->moneyFormat($invoice['tax'], $invoice['currency']);
            $data['success_url']        = $this->config['return_url'];
            $data['cancel_url']         = $this->config['cancel_url'];
            $data['ipn_url']            = $this->config['notify_url'];
            $data['invoice']            = $invoice['id'];
        }
       
        return $this->_generateForm('https://www.coinpayments.net/index.php', $data);
    }
   
    private function _errorAndDie($error_msg) {
    if ($this->config['debug_email']) {
$report = "AUTH User: |".$_SERVER['PHP_AUTH_USER']."|\n";
$report .= "AUTH Pass: |".$_SERVER['PHP_AUTH_PW']."|\n\n";

$report .= "Error Message: ".$error_msg."\n\n";

$report .= "POST Fields\n\n";
foreach ($_POST as $key => $value) {
$report .= $key . '=' . html_entity_decode($value, ENT_QUOTES, 'UTF-8'). "\n";
}

@mail($this->config['debug_email'], "CoinPayments.net Invalid IPN", $report);
}

throw new Exception('IPN Error: '.$error_msg);
// just in case
die('IPN Error: '.$error_msg);
    }

    public function processTransaction($api_admin, $id, $data, $gateway_id)
    {
      $ipn = $data['post'];
    if (!$this->_is_ipn_valid($ipn)) {
$this->_errorAndDie($this->error_msg);
}

  if (!isset($ipn['ipn_type']) || $ipn['ipn_type'] != 'button') {
$this->_errorAndDie('ipn_type != button, ignored.');
  }

      $tx = $api_admin->invoice_transaction_get(array('id'=>$id));
     
      if ($tx['status'] == 'processed') {
$this->_errorAndDie('Transaction has already been processed...');
      }

      if(!$tx['invoice_id']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'invoice_id'=>$data['get']['bb_invoice_id']));
}
       
if(!$tx['type']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'type'=>$ipn['ipn_type']));
}
       
if(!$tx['txn_id']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'txn_id'=>$ipn['txn_id']));
}
       
if(!$tx['txn_status']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'txn_status'=>$ipn['status_text']));
}
       
if(!$tx['amount']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'amount'=>$ipn['amount1']));
}
       
if(!$tx['currency']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'currency'=>$ipn['currency1']));
}

$invoice = $api_admin->invoice_get(array('id'=>$data['get']['bb_invoice_id']));
$client_id = $invoice['client']['id'];
if ($invoice['currency'] != $ipn['currency1']) {
$api_admin->invoice_transaction_update(array('id'=>$id, 'error'=>'Original currency does not match invoice currency!'));
$this->_errorAndDie('Original currency does not match invoice currency!');
}

$status = intval($ipn['status']);
if ($status >= 100 || $status == 2) {
        $bd = array(
            'id'            =>  $client_id,
            'amount'        =>  $ipn['amount1'],
            'description'   =>  'CoinPayments transaction '.$ipn['txn_id'],
            'type'          =>  'CoinPayments',
            'rel_id'        =>  $ipn['txn_id'],
        );
        $api_admin->client_balance_add_funds($bd);
        $api_admin->invoice_batch_pay_with_credits(array('client_id'=>$client_id));
        $d = array(
            'id'        => $id,
            'error'     => '',
            'error_code'=> '',
            'status'    => 'processed',
            'updated_at'=> date('c'),
        );
        $api_admin->invoice_transaction_update($d);                   
} else if ($status >= 0) {
        $d = array(
            'id'        => $id,
            'error'     => '',
            'error_code'=> '',
            'status'    => 'pending',
            'updated_at'=> date('c'),
        );
        $api_admin->invoice_transaction_update($d);                   
} else {
        $d = array(
            'id'        => $id,
            'error'     => '',
            'error_code'=> '',
            'status'    => 'canceled',
            'updated_at'=> date('c'),
        );
        $api_admin->invoice_transaction_update($d);                   
}
    }

    private function _is_ipn_valid($ipn)
    {   
if (!isset($ipn['ipn_mode'])) {
$this->error_msg  = 'IPN received with no ipn_mode.';
return FALSE;
}
if ($ipn['ipn_mode'] == 'hmac') {
if (!isset($_SERVER['HTTP_HMAC']) || empty($_SERVER['HTTP_HMAC'])) {
$this->error_msg  = 'No HMAC signature received.';
return FALSE;
}

$request = file_get_contents('php://input');
if ($request === FALSE || empty($request)) {
$this->error_msg  = 'Error reading POST data';
return FALSE;
}

$merchant = isset($ipn['merchant']) ? $ipn['merchant']:'';
if (empty($merchant)) {
$this->error_msg  = 'No Merchant ID passed';
return FALSE;
}
if ($merchant != trim($this->config['merchant_id'])) {
$this->error_msg  = 'Invalid Merchant ID';
return FALSE;
}

$hmac = hash_hmac("sha512", $request, trim($this->config['ipn_secret']));
if ($hmac != $_SERVER['HTTP_HMAC']) {
$this->error_msg  = 'HMAC signature does not match';
return FALSE;
}

return TRUE;
} else if ($ipn['ipn_mode'] == 'httpauth') {
if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] == trim($this->config['merchant_id'])) {
if (isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_PW'] == trim($this->config['ipn_secret'])) {
$merchant = isset($ipn['merchant']) ? $ipn['merchant']:'';
if (empty($merchant)) {
$this->error_msg  = 'No Merchant ID passed';
return FALSE;
}
if ($merchant != trim($this->config['merchant_id'])) {
$this->error_msg  = 'Invalid Merchant ID';
return FALSE;
}
return TRUE;
} else {
$this->error_msg  = 'IPN Secret not correct or no HTTP Auth variables passed. If you are using PHP in CGI mode try the HMAC method.';
}
} else {
$this->error_msg  = 'Merchant ID not correct or no HTTP Auth variables passed. If you are using PHP in CGI mode try the HMAC method.';
}
} else {
$this->error_msg  = 'Unknown ipn_mode.';
}
return FALSE;   
    }

    private function moneyFormat($amount, $currency)
    {
        return number_format($amount, 2, '.', '');
    }
   
private function _escapeForForm($data) {
if (defined('ENT_HTML401')) {
return htmlspecialchars($data,ENT_QUOTES|ENT_HTML401,'UTF-8');
} else {
return htmlspecialchars($data,ENT_QUOTES,'UTF-8');
}
}

    private function _generateForm($url, $data, $method = 'post')
    {
        $form  = '';
        $form .= '<form name="coinpayments_payment_form" action="'.$url.'" method="'.$method.'">' . PHP_EOL;
        foreach($data as $key => $value) {
            $form .= sprintf('<input type="hidden" name="%s" value="%s" />', $this->_escapeForForm($key), $this->_escapeForForm($value)) . PHP_EOL;
        }
        $form .=  '<input class="bb-button bb-button-submit" type="submit" value="Pay with Bitcoin, Litecoin, or other altcoins via CoinPayments.net" id="coinpayments_payment_button"/>'. PHP_EOL;
        $form .=  '</form>' . PHP_EOL . PHP_EOL;

        if(isset($this->config['auto_redirect']) && $this->config['auto_redirect']) {
            $form .= sprintf('<h2>%s</h2>', __('Redirecting to CoinPayments.net'));
            $form .= "<script type='text/javascript'>$(document).ready(function(){    document.getElementById('coinpayments_payment_button').style.display = 'none';    document.forms['coinpayments_payment_form'].submit();});</script>";
        }

        return $form;
    }
}


<-------------- Code End -------------------->