Tuesday 18 October 2011

Check user login with php


It is important to check whether the user is logged in for same security pages. like edit profile,friend etc.
If user is not logged in page is redirect to login page. Following code is useful for php websites.



function checked_login() {
 if(!isset($_SESSION['id'])) {
  ?>
   <script type="text/javascript" language="javascript">
    alert("<?php echo "Please Login ?>");
    window.location.href='<?php echo _BASEURL_; ?>/login.php';
   </script>
  <?
 //redirect2page('index.php');
 }
 }
define('_BASEURL_','http://localhost/hato1/'); //protocol required (http://)

How to call checked_login() function
<?php
session_start();ob_start();
checked_login();

No comments:

Post a Comment