How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)

Questions by mrbaliram   answers by mrbaliram

Showing Answers 1 - 23 of 23 Answers

Jai Ganesh.M

  • Apr 29th, 2006
 

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.

  Was this answer useful?  Yes

Gerald Scheuerman

  • Aug 24th, 2006
 

Use the PHP array: $HTTP_SERVER_VARS. More specifically: $HTTP_SERVER_VARS['PHP_AUTH_USER'] when using authentication for the page resource.

  Was this answer useful?  Yes

Satyendra Pandey

  • Jul 19th, 2007
 

The easiest way is to maintain the session. When the user login you can register user name in the session after validation. and then check if session is registered then the user is logged in otherwise not.

nasirmajor

  • Feb 4th, 2008
 

The easiest way is to maintain the session. When the user login you can register user name in the session after validation. and then check if session is registered then the user is logged in otherwise not........
======
2nd part: and after login i want to go in current page(same page. where i was working)

answer: use  $_SERVER['HTTP_REFERER'] to get variable and use header function to redirect to current page working on.

  Was this answer useful?  Yes

You can store the login information in session.
For checking whether the user is logged in or not, you may add the checking code in a seperate file and include in all the php filess. Usually including this file in a header file is enough if you follow standards.

For redirection, you may pass the url/php filename with the query string itself.

-Praveen - NinethSense

  Was this answer useful?  Yes

Its very simple to check whether user is logged in or not.
U can make a seperate page called session.php and called this file on every page even better is to make a template page where you once called this page it will be applicable to all pages which uses this template.
In that file you can check whether user is logged in or not by using session.

function chk_login()
{ $user=$_REQUEST[user];
 $pass=$_REQUEST[pass];
$SQL = "SELECT * FROM users where password= '$_REQUEST[pass]'"; if(eq($SQL,$rs)==0)
{#incorrect pass show_login("Incorrect Password. Please try again!");
 return;
}
else
{#correct pass $_SESSION['user'] = $user;
listview("Welcome! $_REQUEST[user] , You have successfully logged in"); } }

-------- and further we check
if($_SESSION['user'] =="")
//invalid user
else
//user is authenticated
----------------------------------

  Was this answer useful?  Yes

abc

  • Sep 12th, 2011
 

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions