Tuesday, August 27, 2013

How to Logout Via php

<?php
 // If the user is logged in, delete the session vars to log them out
  session_start();
  if (isset($_SESSION['agent_id'])) {
    // Delete the session vars by clearing the $_SESSION array
    $_SESSION = array();

       if (isset($_COOKIE[session_name()])) {
      setcookie(session_name(), '');
    }

    // Destroy the session
    session_destroy();
  }


  setcookie('agent_id', '');
  setcookie('username', '');
   // Redirect to the home page
  $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php?data=true';
  header('Location: ' . $home_url);
?>

------------

and for login via php

Define Connection Variable in php

<?php
  // Define database connection constants
  define('DB_HOST', 'localhost');
  define('DB_USER', 'hemanjosko');
  define('DB_PASSWORD', 'password');
  define('DB_NAME', 'database-name');
?>

connect.php
-------------------------------------

   $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

you may include this to anywhere, where you want to add the connection of php to mysql

How to Login Via php

<?php  require_once('connect.php'); //add connection variables

  // If the user isn't logged in, try to log them in


      // Connect to the database
    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

      // Grab the user-entered log-in data
      $user_username = mysqli_real_escape_string($dbc, trim($_POST['username']));
      $user_password = mysqli_real_escape_string($dbc, trim($_POST['password']));

      if(!empty($user_username)) {
 if(!empty($user_password)) {
  // Look up the username and password in the database
        $query = "SELECT agent_id, username FROM hj_buses_agent WHERE username = '$user_username' AND password = '$user_password'";
        $data = mysqli_query($dbc, $query);

        if(mysqli_num_rows($data) == 1) {
          // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page
          $row = mysqli_fetch_array($data);
        $_SESSION['agent_id'] = $row['agent_id'];
          $_SESSION['username'] = $row['username'];
          setcookie('agent_id', $row['agent_id']);
 setcookie('username', $row['username']);  
          $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
          header('Location: ' . $home_url);
          }
        else {
          // The username/password are incorrect so set an error message
        $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/login.php?data=true';
          header('Location: ' . $home_url);
}
 }else

 {
 echo'<script type="text/javascript">alert("Enter Correct Password");</script>';
 }
 }
      else {
        // The username/password weren't entered so set an error message
     echo'<script type="text/javascript">alert("Enter Username & Password");</script>';
      } ?>

Wednesday, July 3, 2013

HTML (HYPER TEXT MARKUP LANGUAGE) format of writing html

<html>

      <head>

             <title> Write Title Here</title>

       </head>

<body>    

Write html tags here..



</body>


</html>

Write this code in any editor, notepad, notepad++, etc.
And save this format to .html or .htm file extension. Now your html file is generated.

Saturday, June 29, 2013

Verify Value is Entered or Not By Javascript

<html>
<head>
<title>user_login</title>
<script language="javascript" type="text/javascript"/>
function validate()
{
    if(document.getelementByID('t1').value.length==0)
{
alert(" username is required");
return false;
}

  else {
  if(document.getelementById('t2').value.length==0)

    alert("password is requires");
return false;
}
alert("login successfully");
return true;

}




</script>
</head>
<body>
<form  name="frm" action="validation in js.php" method="post">
Enter Username <input type="text" name="t1" id="t1"/>
Enter Password <input type="password" name="t2" id="t2"/>
<input type="submit" name="S1" id="S1" value="Register"
onclick="return validate()"/>
</form>



</body>
</html>

Friday, June 28, 2013

What is Pagination - PHP

Pagination  :

If Database Tables contains more rows like hundreds

Than your output of that table would be heavy in webpages, 

Than pagination works : Pagination gives you a power to breakup the database tables to php pages break into parts with limit query. 

And You would divide that hundreds of table into like limit of 10 or 20 per page.

Than Limit works like 0 to 9, 10 to 19, etc...

and your pagination works like

<<prev      1    2    3    4    5   .... 1001   1002     next>> 

Wednesday, June 26, 2013

Add javascript in you html

For adding javascript code in your html, You just have to put the script tag in html

For example

<script type="text/javascipt">



<!-- write javascript code here -->


</script>


Put this script tag in your html page head tag section. 

<html>
<head>
<script type="text/javascipt">



<!-- write javascript code here -->


</script>

</head>
<body>
<!-- html code here -->
</body>

</html>


Or You may add through an link too..

<html>
<head>
<link rel="text/javascript" href="new.js">

</head>
<body>
<!-- html code here -->
</body>

</html>


And code you data in new.js

<!-- write javascript code here -->

as a separate file