Tech blog

PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Wednesday 19 November 2014

How To send sms using API in PHP??

No comments :
Today we guys mostly use sms services available on internet like way2sms,160by2.but have we ever thought to take them in our webapplications.

In PHP,We can do this with simple code of thirdparty api..
Here i have created simple code which sends sms to given mobile number using clickatell API.




Here is code:

<?php
    $user = "xxxxxx";
    $password = "xxxxxx";
    $api_id = "xxxxxx";
    $baseurl ="http://api.clickatell.com";

    $text = urlencode("This is an example message");
    $to = "+919408046690";

    // auth call
    $url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";

    // do auth call
    $ret = file($url);

    // explode our response. return string is on first line of the data returned
    $sess = explode(":",$ret[0]);
    if ($sess[0] == "OK") {

        $sess_id = trim($sess[1]); // remove any whitespace
        $url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";

        // do sendmsg call
        $ret = file($url);
        $send = explode(":",$ret[0]);

        if ($send[0] == "ID") {
            echo "successnmessage ID: ". $send[1];
        } else {
            echo "send message failed";
        }
    } else {
        echo "Authentication failure: ". $ret[0];
    }
?>

In this code,user,password and api id are needed for code,which is available on www.clickatell.com/
site.

Happy Coding guys!!! 

Simple Login With PHP

No comments :

Hello Friends,
Today I am going to show you simple login with php session and html form.First we will create html form as follow:



<form method="post" action="index.php" name="form1" id="form1">
      <h2>Login</h2>
      <p> 
        <input type="text" placeholder="Username" name="username" id="username">
      </p>
      <p> 
        <input type="password" placeholder="Password" name="pass" id="pass">
      </p>
      <input type="submit" name="submit1" id="submit1" value="Login" class="button"/>
    </form>

Here on above form there is two fields username and password.User will enter username and password into form and submit it to page.

After submitting form to same page,here see how following code will accept data.

if(isset($_POST['submit1']))
{
$username=addslashes($_POST['username']);
$pass=addslashes($_POST['pass']);
$sel="select * from admin where username='$username' AND password='$pass'";
$res=mysql_query($sel) or die(mysql_error());
$total=mysql_num_rows($res);
if($total > 0)
{
while($rows=mysql_fetch_array($res))
{
session_start();
$_SESSION['ID']=$rows['id'];
   $_SESSION['USERNAME']=$rows['username'];
header("location:dashboard.php");
}

}
}

Please see structure of table admin as follow: