This topic is locked
[SOLVED]

 Bypass Login Page if User is Logged in

12/18/2007 3:47:37 AM
PHPRunner General questions
R
run4sbc author

I had someone ask me if I could do this, and I read around the forums but couldnt find anything like it for PHPRunner.
I want to create a session so that once the user logs in, if they go back to the homepage (login.php) they will automatically be sent to the menu field. They dont want to have to log in again, which makes sense.
I couldnt figure out how I would be able to do it and couldnt find much on the forums about it, so I figured I'd see if someone had done this before.
Thanks!

Cody

J
Jane 12/18/2007

Cody,
you can do it using COOKIES:

http://php.net/manual/en/features.cookies.php
Save UserID of logged user in the COOKIES, then check it in the Login page: Before process event, fill all required $_SESSION variables and redirect to menu page.

R
run4sbc author 12/18/2007

So I have a cookie
<?php

$value = 'UserLogin';
setcookie("Username", $value);

setcookie("Password", $value, time()+3600); / expire in 1 hour /

setcookie("UserID", $value, time()+3600, ".flashresultsonline.com", 1);

?>
Or something like that right?
Then in the Login page: Before process event I call the variables in...
// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
//** Custom code ****

$values["Username"] = $_SESSION["Username"];

$values["Password"] = $_SESSION["Password"];

$values["UserID"] = $_SESSION["UserID"];
return true;
// return true if you like to proceed with adding new record

// return false otherwise
And have a redirect code at the bottom on of that code? I've been reading through the Cookie manual and am working on it. I just want to make sure I'm semi clear on what I have to do. I'm still in the learning stage for most of this more advanced stuff lol.
Thanks for all your help Jane!!
Cody

J
Jane 12/19/2007

Cody,
you need to save real username of logged in user in the COOOKIES:

if (!@$_COOKIES["Username"])

setcookie("Username", $_SESSION["UserID"]);



You can add this code to the Menu page: Before process event.
Then check your COOKIES in the Login page: Before process event.

Here is a sample:

if (@$_COOKIES["Username"])

{

$_SESSION["UserID"] =$_COOKIES["Username"];

//you need to fill another $_SESSION variables if you use group security settings

header("Location: menu.php");

exit();

}