Articles by "PHP"

2019 4G LTE 4G VoLTE 5G 7th Pay Commission Aadhaar Actor Wallpapers Actress Wallpaper Adriana Lima AdSense Ahoi Ashtami Airtel Akshay Kumar Alcatel Alexa Rank Amazon Android Android Pie Android Q Anna university Antivirus Anushka Sharma Apple Apps Army Army App Asus Athletics Auto Auto Insurance Avengers Axis Bank Bajaj Bang Bang Reloaded Bank Battery Bhai Dooj Katha Bharti Bhumi Pednekar Big Bazaar Bing BlackBerry Blogger BlogSpot Bluetooth BoB Bollywood Boot Boxing Browser Bsnl Budget Budhvar Business buy Camera Car Car Loan Cash Celebrity CEO Chandra Grahan Channels Chhath chrome Comparisons Computer Coolpad Credit Cricket Crime Deepika Padukone Defence Detel Dhanteras Diamond Crypto Diwali DNS setting Domain Donate Doogee DTH DTH Activation DTH Installation DTH Plans in India Dusshera Earn Money Education Electronics Email Entertinment Ex-serviceman Extensions Facebook Festivals Flipkart Foldable Smartphone Food Funny Gadgets Galaxy Galaxy S8 Game Ganesh ganesh chaturthi Gionee Gmail God Google Google + Google Assistant Google Drive Google Duo Google Pixel Google Tez Google Voice Govardhan Puja GST GTA Guide Guruvar Hamraaz hamraaz app hamraaz app download hamraaz army hamraaz army app hamraaz army app download Hamraaz Army App version 6 Apk Happy New Year Hariyali Teej Hartalika Teej Harvard University HDFC Bank Headphones Health Heena Sidhu Hello App Help Hindi History Hockey Holi Katha Hollywood Home Loan Honor HostGator Hosting Hrithik Roshan HTC Huawei humraaz app iBall IBM ICICI Bank Idea India indian army app Infinix InFocus Information Infosys Instagram Insurance Intel Internet Intex Mobile iPad iPhone iPhone 8 IPL IRCTC iVoomi Janmashtami Javascript JBL Jio Jio GigaFiber JioRail JioSaavn Jokes Karbonn Kareena Kapoor Kartik Purnima Karva Chauth Karwa Chauth Kasam Tere Pyaar Ki Katrina Kaif Kendall Jenner Kimbho Kodak Kumkum Bhagya Landline Laptop Lava Lenovo LET LG Library of Congress Lifestyle Linkedin Lisa Haydon Loans Macbook Maha Shivratri Map Market Mary Kom Massachusetts Institute of Technology Meizu Messages Mi Micromax Microsoft Mobile Mokshada Ekadashi Money Motorcycles Motorola Movie Music Narendra Modi Narsingh Jayanti Nature Naukri Navratri Netflix Network News Nexus Nia Sharma Nokia Notifications OBC Ocean Office Offrs OMG OnePlus Online Opera Oppo Oreo Android Orkut OS OxygenOS Padmavati PagalWorld PAN Panasonic Passwords Patanjali Pay Payment Paypal Paytm PC PDF Pendrive Personal Loan Phone Photo PHP Pixel Plan PNB Bank PNR Poco Poster PPC Pradosh Pragya Jaiswal Prepaid Princeton University Printer Priyanka Chopra PUBG Qualcomm Quora Quotes Race 3 Railway Rambha Tritiya Vrat Realme Recruitment Redmi Relationship Religious Restore Results Review Rule Sai Dharam Tej Saina Nehwal Salman Khan Samsung Sanusha Sawan Somvar Vrat SBI Bank Script Sell SEO Serial Server Shahid Kapoor Shanivar Sharad Poornima Sharp Shiv Shreyasi Singh Shruti Haasan Sim Smart Android TV Smartphones Snapchat Social Software Somvar Sonakshi Sinha Sonam Kapoor Soney Songs Sony Xperia Space Speakers Specifications Sports Sql Stanford University State Bank of India Stickers Story Sunny Leone Surabhi Sushant Singh Rajput Swadeshi Tax Tech Technology Tecno Telugu Tiger Shroff Tiger Zinda Hai Tips Tollywood Tool Top Trending People Trading Trai TRAI Rules for cable TV Trailer Trends Truecaller Tubelight Tulsi Vivah Tv Twitter Typing Uber University of Oxford UP Board Update USB Vacancies Valentines Day Verizon Vertu Video Vijayadashami Virat Kohli Virgin Visas Vivo Vodafone VPN Vrat Katha Vrat Vidhi Wallpaper War Wayback Machine WhatsApp Wi-Fi Windows Windows 10 Wipro Wireless WordPress workstation WWE Xiaomi Xiaomi Mi 6 Yeh Hai Mohabbatein Yo Yo Honey Singh Yoga YotaPhone YouTube ZTE
Showing posts with label PHP. Show all posts

June 22, 2017
This post about "Sending Mail using SMTP and PHP". Now you can send emails with SMTP authentication using this script. Every mail needed server authentication, So you have to buy mail server. It's very useful you can implement this on your web projects.

This tutorial contains three files.

- Index.php
- SMTPconfig.php // SMTP Server Cofiguration
- SMTPClass.php // SMTP Mail Sending Class

SMTPconfig.php
You have to change SMTP server details.
<?php
//Server Address
$SmtpServer="127.0.0.1";
$SmtpPort="25"; //default
$SmtpUser="username";
$SmtpPass="password";
?>

SMTPclass.php
SMTP mail sending class.
<?php
class SMTPClient
{

function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{

$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;

if ($SmtpPort == "")
{
$this->PortSMTP = 25;
}
else
{
$this->PortSMTP = $SmtpPort;
}
}

function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>

index.php
<?php
include('SMTPconfig.php');
include('SMTPClass.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
?>
<form method="post" action="">
To:<input type="text" name="to" />
From :<input type='text' name="from" />
Subject :<input type='text' name="sub" />
Message :<textarea name="message"></textarea>
<input type="submit" value=" Send " />
</form>

June 22, 2017
Are you looking for PHP login script, in this post I want to discuss how to create a simple PHP login with welcome page using MySQL database. This will explain you creating user tables, posting form values and storing and destroying the session values.

Database
MySQL admin table columns id, username, passcode.
CREATE TABLE admin
(
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(30) UNIQUE,
passcode VARCHAR(30)
);

Config.php
Database configuration file.
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'database');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

Login.php
Contains PHP and HTML code.
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$myusername=mysqli_real_escape_string($db,$_POST['username']);
$mypassword=mysqli_real_escape_string($db,$_POST['password']);
$passwordSecure=md5($mypassword);
$sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$passwordSecure'";
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$active=$row['active'];
$count=mysqli_num_rows($result);


// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_user']=$myusername;

header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<form action="" method="post">
<label>UserName :</label>
<input type="text" name="username"/><br />
<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Submit "/><br />
</form>

lock.php
Session verification. If no session value page redirect to login.php
<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];

$ses_sql=mysqli_query($db,"select username from admin where username='$user_check' ");

$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

$login_session=$row['username'];

if(!isset($login_session))
{
header("Location: login.php");
}
?>


welcome.php

<?php
include('lock.php');
?>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
</body>

logout.php
SignOut Destroy the session value.
<?php
session_start();
if(session_destroy())
{
header("Location: login.php");
}
?>

June 22, 2017
I'm using this PHP function to redirect text URLs as Links with Regular Expression validation. Just five lines of code, It's very useful.

To_Link.php
Contains PHP Code $text value validating with Regular Expressions 
<?php
function To_Link($text)
{
$text = html_entity_decode($text);
$text = " ".$text;
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $text);
return $text;
}
?>


index.php
You have to include To_link.php. Using function To_Link('You Text and URL')
<?php
include('To_Link.php');

$text='jQuery and Ajax best 9lessons http://tinyurl.com/naottn';

echo To_Link($text);

?>

June 22, 2017
This is PHP function split_url_fuction() writter for twitter like application that i am developing, useful to split URL from the updated sentence(posted message), then URL changing like tinyurl and link to the resource.

This function is break up the URL from the sentence, if the URL string length greater than 30 words it's change like TinyURL. 

Step 1. You have to include the file split_url_function.php into the PHP file that will use the function.
include("split_url_function.php");

Now you have to pass the updated data:
<?php echo  split_url_function($message); ?>

Here $message is the value from a SQL query.( Table structure )

This is the code of split_url_funtion() PHP function:

<?php

include("tiny_url.php"); //tinyurl function
function split_url_function($update  
{
    //----URL Checking in Update.
    $http= substr_count($update,"http://");
    $www=substr_count($update,"www.");
    $htp=substr_count($update,"http//");

    if($http==1)
   {
         $str="http://";
         $h=1;
    }
    if($www==1)
   {
      $str="www.";
      $w=1;
    }
    if($h==1 && $w==1)
    {
       $str='http://www.'//--Both
    }
    if($htp==1)
    {
          $comb_str=$update; //--No url
     }
//--- explode the update 
$fa=explode($str,$update);
$cnt_fa=count($fa);
$se=explode(" ",$fa[1]);
$cnt_se=count($se);

for($i=1;$i<=$cnt_se;$i++)
{
     $sep.=$se[$i].' ';
}
     // Split URL 
      $split_url=$str.$se[0];
      if($split_url=='')
     {
         $final_update=$update;
      }
      else
    {
         // URL link sting lenght verfication
         if(strlen($split_url)>=30)
        {
             $tiny = tiny_url($split_url);
$final_update=$fa[0].'<a href="'.$tiny.'" target="_blank">'.$tiny.'</a>'.$sep;
echo $final_update;
         }
         else
        {
          // Combine all the explode parts
$final_update=$fa[0].'<a href="'.$split_url.'" target="_blank">'.$split_url.'</a>'.$sep;
echo $final_update;
         }
     }
}
?>

tiny_url.php Original reference http://davidwalsh.name/create-tiny-url-php
<?php
function tiny_url($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>

June 22, 2017
In this post I want to explain how to insert encrypted password while registration and accessing the same with login time. I'm just storing encrypted user password in database. Demo username ='test' and password = 'test'

Database
MySQL admin table columns id, username, passcode.
CREATE TABLE admin
(
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE,
passcode VARCHAR(50)
);

Encrypted Password
Here database table admin password:test encrypted and storing like this

registration.php
Contains PHP and HTML code. Just inserting form values into database table admin
<?php
include("db.php");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$password=md5($password); // Encrypted Password
$sql="Insert into admin(username,passcode) values('$username','$password');";
$result=mysqli_query($db,$sql);
echo "Registration Successfully";
}
?>
<form action="registration.php" method="post">
<label>UserName :</label>
<input type="text" name="username"/><br />


<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Registration "/><br />
</form>

login.php
Login Script accessing the encrypted password.
<?php
include("db.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$password=md5($password); // Encrypted Password
$sql="SELECT id FROM admin WHERE username='$username' and passcode='$password'";
$result=mysqli_query($db,$sql);
$count=mysqli_num_rows($db,$result);

// If result matched $username and $password, table row must be 1 row
if($count==1)
{
header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<form action="login.php" method="post">
<label>UserName :</label>
<input type="text" name="username"/><br />
<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Login "/><br />
</form>

db.php
Database configuration file.
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'database');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

MsnTarGet.com

Satish Kumar

Contact Form

Name

Email *

Message *

Powered by Blogger.