php - Re-directing to certain page if logged in -


i have main page has log in link on takes user login page. however, if user logged in want take user page, example info page.

i have function:

function logged_in_redirect() { if (logged_in() === true) {     header('location: client.php');     exit(); } } 

i'm wondering put this? i've tried pretty everything. if put on login page, not redirect me when logged on. i've tried adding onclick function link on home page didn't work.

this logged_in() function:

function logged_in() { return (isset($_session['user_id'])) ? true : false; } 

any suggestions?

edit:

i have fixed problem making button on home page link test.php file has code:

<?php include 'core/init.php';  if (isset($_session["user_id"])) {     header('location: client.php'); } else {     header('location: info.php'); }  ?> 

is there way around this?

if session set , user authenticated work.

you don't need function check whether login set unless have common file handling authentication related stuff , other files calling function check if user logged in..

login page:

<?php   //check if user loggedin if(isset($_session["user_id"]){   //assuming client.php in same directoy   header("location: client.php"); //you don't need exit since redirected }  //your login stuff. if user_id not set part executed  ?> 

also don't forget destroy session once log out..


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -