Zen Cart Logo
Forums / General Questions / PHP How do we check for logged in?

PHP How do we check for logged in?

Locked

Views: 1,404

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
4 Sep 2008, 1:44 AM
#1
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

PHP How do we check for logged in?

Hi All,
I have a little project going here. I need to know how to check to see if a customer is logged in please.

Thanks in advance,
John

4 Sep 2008, 1:58 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: PHP How do we check for logged in?

If the customer is logged in, then the value of $_SESSION['customer_id'] will contain their customer number.
If that value is blank or is not set, they're not logged in.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 Sep 2008, 2:00 AM
#3
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: PHP How do we check for logged in?

So this should work then?

echo 'Logged in customer id is: ' . $_SESSION['customers_id'];

It doesn't give me the id. Why not?

Thanks Dr.

       John
4 Sep 2008, 2:03 AM
#4
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: PHP How do we check for logged in?

Ahhh that's why it wasn't working!

echo 'Logged in customer id is: ' . $_SESSION['customers_id'];
should be
echo 'Logged in customer id is: ' . $_SESSION['customer_id'];

I have eyes like an Eagle! LOL

Thanks. I'm sure I'll be back for more later.

Thanks again,
John

4 Sep 2008, 4:29 AM
#6
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: PHP How do we check for logged in?

Hi All,
Is this a good way to test if the customer is logged in?

<?php

  if ($_SESSION['customer_id'] < 1) {
   echo 'Not Logged In!';
   } else {
   $testQuery = mysql_query("SELECT customers_firstname FROM customers WHERE customers_id = '".(int)$_SESSION['customer_id'] ."'");
   while ($customerName = mysql_fetch_assoc($testQuery)) {
   echo $customerName['customers_firstname'] ." ". $_SESSION['customer_id'];
   }
   }
   
   ?>

Please don't be to harsh I'm learning and I'm also sensitive.:yes:

Thanks,
John

4 Sep 2008, 4:38 AM
#7
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: PHP How do we check for logged in?

Also:

I have cloned the About Us page. In the templates > MyTemp > templates >tpl_new_page.php I am trying to submit a form.

This is the php I'm using to submit. However it is not writing to the DB. Am I missing something here? Like a db connect? I figure we're already connected at this point.

   <?php
   $clientCustomersID = $_SESSION['customer_id'];
   $websiteURL = serialize($_POST['websiteUrl']);
   $keywords = serialize($_POST['keywords']);
   $description = serialize($_POST['description']);
   
   //Inject Customers website into client side DB
   
      if($_SERVER['REQUEST_METHOD']=='POST') {
   
      $qur="INSERT INTO websites (`customers_id`,`url`,`keywords`,`description`)values ('$clientCustomersID','$websiteURL','$keywords','$description')";
   }

  ?>
```Thanks,
            John
4 Sep 2008, 4:56 AM
#8
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: PHP How do we check for logged in?

Okay,
Got this part. Got it to inject. May have more questions here in a bit though.

Thanks,
John