Jump to content

Help needed on PHP session


kks_krishna

Recommended Posts

HI,

 

i want to implement session in my site. If for a particular page should be accesses by only the loged in user. so I need to check whether the user is logged in or I shoud forward to Registration page or login page.

 

Once the user is logged in we can use the userid to log the activities. How can we do this?

Link to comment
Share on other sites

Don't use @ for suppressing errors.

 

If you are checking input variables (_GET, _POST, _COOKIE, _SESSION etc) values always use isset function and then check it's value.

So instead of:

if ( @$_SESSION['auth'] != "TRUE" )

 

Do:

if ( isset($_SESSION['auth']) && $_SESSION['auth'] != "TRUE" )

 

@ should only be used as a last resort.

Link to comment
Share on other sites

Please check the code whether its correct :

 

<?php
include("UsersOperations.php");
$user = new UsersOperations;
$user_name = $_GET['user_name'];
$pass = $_GET['pass'];
$result = $user->check_user($user_name,$pass);
if($result==1)
{
session_start();
$_SESSION['auth'] = TRUE;
$_SESSION['user_name'] = $user_name;
header("Location: ../index.php");
die();
}
?>

 

<?php 
			$var = $_SESSION['user_name']; 			
			print($var);
		?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.