Post by ctellier » Fri Oct 23, 2009 10:49 am

Hi I have a question. I would like my homepage (not my store index.php) to be able to recognize if a customer is logged in. How would I do this? I know it has somthing to do with sessions and or cookies, but I just dont know how to go about it. ???

site is set up like this:
Homepage: /index.php
Store: /store/index.php

Thanks

User avatar
New member

Posts

Joined
Sun Oct 18, 2009 9:36 am
Location - Wisconsin

Post by ctellier » Fri Oct 23, 2009 10:21 pm

Bump.

User avatar
New member

Posts

Joined
Sun Oct 18, 2009 9:36 am
Location - Wisconsin

Post by Qphoria » Fri Oct 23, 2009 11:58 pm

It uses the php session to store the customer logged in data.
Try the session_start() command on your homepage index.php and i believe it carries over

See the example here: http://php.net/manual/en/function.session-start.php

If logged in, there is a session variable called customer_id

Code: Select all

session_start();
if (isset($_SESSION['customer_id'])) {
echo "Customer is logged in";
}

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by ctellier » Sat Oct 24, 2009 5:03 am

Thanks, works great ;D

User avatar
New member

Posts

Joined
Sun Oct 18, 2009 9:36 am
Location - Wisconsin

Post by Qphoria » Sat Oct 24, 2009 6:38 am

really? wow i hadn't even tested it.. i was going on theory! lol Good to know

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by ctellier » Sat Oct 24, 2009 12:05 pm

Yup, but now I need to figure out how to echo or print the firstname? I have it set up like this...

In my main sites header.php i have this

Code: Select all

<?php
if (isset($_SESSION['customer_id'])) {
	include_once "logged.php";
}
else {
	include_once "notlogged.php";
}
?>
Now if a customer is NOT logged in the notlogged.php shows the email and password inputs. which works fine.

My problem is this, I want to echo the customers name in the logged.php. I tried this but nothing...

Code: Select all

<?php echo $this->data['firstname'];?>
I also tried this :

Code: Select all

<?php echo "Welcome $firstname";?>
only welcome shows up..

User avatar
New member

Posts

Joined
Sun Oct 18, 2009 9:36 am
Location - Wisconsin

Post by Qphoria » Sat Oct 24, 2009 8:45 pm

Well thats all class stuff loaded from the index.php of the cart. You'd basically need to add session variables to the login process to store all these extra stuff you want to access outside of the store, as that is your common variable base between the two.

EDIT: system/helper/customer.php
FIND:

Code: Select all

$this->session->data['customer_id'] = $customer_query->row['customer_id'];
AFTER, ADD:

Code: Select all

$this->session->data['firstname'] = $customer_query->row['firstname'];
Do the same for any other variables you want to work with. You can see a list of all the available data in that same code area

Then in that same file,
FIND:

Code: Select all

unset($this->session->data['customer_id']);
AFTER, ADD:

Code: Select all

unset($this->session->data['firstname']);
And any other variables you added

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by ctellier » Sun Oct 25, 2009 2:38 am

Ok this is how I did the echo

Code: Select all

<span class="dark2">Welcome Back <?php echo ($_SESSION['firstname']);?>!</span>
And it works. Is that the right way to do it?
Thanks alot!

User avatar
New member

Posts

Joined
Sun Oct 18, 2009 9:36 am
Location - Wisconsin

Post by Qphoria » Sun Oct 25, 2009 8:15 pm

Well, if they aren't logged in it might give an error since the variable won't be set. This would be best:

Code: Select all

<span class="dark2">Welcome Back <?php echo (isset($_SESSION['firstname'])) ? $_SESSION['firstname'] : '' ?>!</span>

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by ctellier » Mon Oct 26, 2009 11:46 am

Remember i had this:

Code: Select all

<?php
if (isset($_SESSION['customer_id'])) {
   include_once "logged.php";
}
else {
   include_once "notlogged.php";
}
?>
so if they are not logged it wont even run

Code: Select all

<span class="dark2">Welcome Back <?php echo ($_SESSION['firstname']);?>!</span>
so is that ok? or should i still change the logged.php to what you put?

User avatar
New member

Posts

Joined
Sun Oct 18, 2009 9:36 am
Location - Wisconsin

Post by Qphoria » Mon Oct 26, 2009 12:26 pm

Yea thats fine

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: Semrush [Bot] and 81 guests