Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Google Cloud Messaging for Android

Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas.

 //////////////////////////////////index.php
 <!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
             
            });
            function sendPushNotification(id){
                var data = $('form#'+id).serialize();
                $('form#'+id).unbind('submit');              
                $.ajax({
                    url: "send_message.php",
                    type: 'GET',
                    data: data,
                    beforeSend: function() {
                      
                    },
                    success: function(data, textStatus, xhr) {
                          $('.txt_message').val("");
                    },
                    error: function(xhr, textStatus, errorThrown) {
                      
                    }
                });
                return false;
            }
        </script>
        <style type="text/css">
            .container{
                width: 950px;
                margin: 0 auto;
                padding: 0;
            }
            h1{
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 24px;
                color: #777;
            }
            div.clear{
                clear: both;
            }
            ul.devices{
                margin: 0;
                padding: 0;
            }
            ul.devices li{
                float: left;
                list-style: none;
                border: 1px solid #dedede;
                padding: 10px;
                margin: 0 15px 25px 0;
                border-radius: 3px;
                -webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
                -moz-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
                box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                color: #555;
            }
            ul.devices li label, ul.devices li span{
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 12px;
                font-style: normal;
                font-variant: normal;
                font-weight: bold;
                color: #393939;
                display: block;
                float: left;
            }
            ul.devices li label{
                height: 25px;
                width: 50px;              
            }
            ul.devices li textarea{
                float: left;
                resize: none;
            }
            ul.devices li .send_btn{
                background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0096FF), to(#005DFF));
                background: -webkit-linear-gradient(0% 0%, 0% 100%, from(#0096FF), to(#005DFF));
                background: -moz-linear-gradient(center top, #0096FF, #005DFF);
                background: linear-gradient(#0096FF, #005DFF);
                text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
                border-radius: 3px;
                color: #fff;
            }
        </style>
    </head>
    <body>
        <?php
        include_once 'db_functions.php';
        $db = new DB_Functions();
        $users = $db->getAllUsers();
        if ($users != false)
            $no_of_users = mysql_num_rows($users);
        else
            $no_of_users = 0;
        ?>
        <div class="container">
            <h1>No of Devices Registered: <?php echo $no_of_users; ?></h1>
            <hr/>
            <ul class="devices">
                <?php
                if ($no_of_users > 0) {
                    ?>
                    <?php
                    while ($row = mysql_fetch_array($users)) {
                        ?>
                        <li>
                            <form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $row["id"] ?>')">
                                <label>Name: </label> <span><?php echo $row["name"] ?></span>
                                <div class="clear"></div>
                                <label>Email:</label> <span><?php echo $row["email"] ?></span>
                                <div class="clear"></div>
                                <div class="send_container">                              
                                    <textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea>
                                    <input type="hidden" name="regId" value="<?php echo $row["gcm_regid"] ?>"/>
                                    <input type="submit" class="send_btn" value="Send" onclick=""/>
                                </div>
                            </form>
                        </li>
                    <?php }
                } else { ?>
                    <li>
                        No Users Registered Yet!
                    </li>
                <?php } ?>
            </ul>
        </div>
    </body>
</html>
/////////////////////////////////////////////////////////////////////GCM.php
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if (isset($_GET["regId"]) && isset($_GET["message"])) {
    $regId = $_GET["regId"];
    $message = $_GET["message"];
   
    include_once './GCM.php';
   
    $gcm = new GCM();

    $registatoin_ids = array($regId);
    $message = array("price" => $message);

    $result = $gcm->send_notification($registatoin_ids, $message);

    echo $result;
}
?>

/////////////////////////////////////////////////////////////////send_message.php

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if (isset($_GET["regId"]) && isset($_GET["message"])) {
    $regId = $_GET["regId"];
    $message = $_GET["message"];
   
    include_once './GCM.php';
   
    $gcm = new GCM();

    $registatoin_ids = array($regId);
    $message = array("price" => $message);

    $result = $gcm->send_notification($registatoin_ids, $message);

    echo $result;
}
?>

Google Cloud Messaging for Android

Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas.

Login and Session Control in PHP

Let's see how to manage the Session in Web pages before that that we need to know what is the the Session and why it's need to web pages .Session mean we temporarily save or pass data to verify or to do some other actions  .Session will help to authenticate whether the request to access some other pages come from from authenticated user or else coming from other illegal access



<title>Login Page</title>

<Head><center>Login</center>

<script language="javascript">

    function validate(form)

    {

        var uname=form.uname.value;

        var pword=form.pword.value;

        if(uname==""||pword="")

        {

            alert("please fill all ");

            return false;

        }

        else

        {

            return true;

        }

    }

</script>

</head>

<div>

<body>

<form name="login" Method="POST" OnSubmit="return validate(login)" 
      action="check.php">

<center><table border="1">

<tr><td >Username</td><td><input type="text" name="uname"></td></tr>

<tr><td>PassWord</td><td><input type="text" name="Pword"></td></tr>

<tr><td></td> <td align="right"><input type="submit" value="submit"></td></tr>

</table></center>

</form>

</div>

</body>



/////////////////////////////////////////////check.php



    $uname=$_POST['uname'];

    $pword=$_POST['Pword'];



    $db=mysql_connect('localhost','root','') 
          or die('database connection is error');
    mysql_select_db('sms',$db);
    $sql="select * from usercredentials where Username='$uname'";
    $result1=mysql_query($sql);
    $row=mysql_fetch_array($result1);



    if($pword==$row['Password']&&$row['Privilege']=='admin')

        {
            session_start();
            $_SESSION['uname']=$uname;
            header("location:admin.php");
        }
    else if($pword==$row['Password']&&$row['Privilege']=="student")

        {
            session_start();
            $_SESSION['uname']=$uname;
            header("location:student.php");
        }

    else
        {
            header("location:index.html");
        }
    ?> 
 
 
////////////////////////////////////////////////Logout.php
 
 <?php

    session_start();

    if(isset($_SESSION['uname']))

            {
                session_destroy();
                header("location:index.html");
            }

    else
            {
            header("location:index.html");
            }

?>

Login and Session Control in PHP

Let's see how to manage the Session in Web pages before that that we need to know what is the the Session and why it's need to web pages .Session mean we temporarily save or pass data to verify or to do some other actions  .Session will help to authenticate whether the request to access some other pages come from from authenticated user or else coming from other illegal access

PHP Connection With MySql DataBase








Let's learn to connect the php with MySQL Database to store and retrieve data 
<?php
$host='localhost';
$user='root';
$pass='';
$database_name='user';
?>

<?php
    require_once 'config/config.php';
    $connect = mysql_connect($host,$user,$pass) or die("Connection to server failed");
    mysql_select_db($database_name,$connect) or die("Connection to database failed");
   
    $name = $_POST['name'];
    $phone_no = $_POST['phone'];
    $email = $_POST['email_addr'];
   
    $result=mysql_query("INSERT INTO userdetails(Name,PhoneNo,Email) VALUES ('$name',$phone_no,'$email')",$connect);
    echo $result;
    if($result){
        echo "Successfully inserted";       

    }
    mysql_close($connect);
?>

#main
{
    background-color:#00FF00;
    width:300;
    height:100;
    position:absolute;           
    margin-left:400;
    margin-top:200;
    padding-left:10;
    padding-top:10;
}
#mainbody
{
    background-color:#00FF00;
    width:350;
    height:250;
    position:absolute;           
    margin-left:300;
    margin-top:200;
    padding-left:10;
    padding-top:10;
}
   


<html>
    <head>
        <title>HTML Form</title>
        <link rel="stylesheet" type="text/css" href="style.css" >
        <script src="validation.js" type="text/javascript" xml:space="preserve"></script>
    </head>
    <body bgcolor="#9999CC">
    <div id="mainbody">
        <form name="details" action="insert.php"  onsubmit="return validateFormOnSubmit(details)" method="POST" >
            <p>
            Enter your name:
            <br />
            <input type="text" size=50 name="name" />
            <p>
            Enter your phone:
            <br />
            <input type="text" size=50 name="phone" />
            <p>
            Enter your email address:
            <br />
            <input type="text" size=50 name="email_addr" />
            <p>
            <input type=submit value="submit" />
            <input type=reset value="clear" />
        </form>
    </div>
    </body>
</html>


      

PHP Connection With MySql DataBase