Post by RichMo » Sun Jul 15, 2012 2:05 am

Hi,

My opencart shop is installed as "example.com/shop", and I would like to be able to use the opencart login to allow access to other parts of my site. i.e. pages that are not within the /shop/ directory.

Is this possible?

For example, in a page such as example.com/example.php...

if (user is logged on) {
echo "Welcome Username";
} else {
echo "Welcome Guest, please log in";
}

I've tried the following code in a file (example.com/test.php), but I think I must need to call some functions first, but I'm not sure where to start... (it says logged is undefined)

Code: Select all

<?
// This file is example.com/test.php
// Shop is at  example.com/shop/

include_once ("shop/config.php");
include_once ("shop/system/startup.php");
if (!$logged) {
   echo "You are NOT logged in";
} else {
   echo "You are logged in";
}
?>
Last edited by RichMo on Wed Jul 18, 2012 7:26 pm, edited 2 times in total.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by Avvici » Mon Jul 16, 2012 7:46 pm

If you want to test a session on whether it is set then you have to start the session first by session_start(); I don't know how cube cart start's its session. Are you saying that you want to login to CUBE CART with Open Cart login? Or login to Open Cart to access CUBE CART?

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by RichMo » Wed Jul 18, 2012 7:25 pm

No, I want to get rid of Cubecart totally. It is rubbish. I made typo in the above... fixed now

I want to use opencart instead. I just need to be able to load the opencart sessions from pages that are not within the opencart folder.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by RichMo » Thu Jul 19, 2012 4:33 am

Well I think I sorted it. This is the contents of my test.php file...

Code: Select all

<?
// Version
define('VERSION', '1.5.3.1');

// Configuration
require_once('shop/config.php');

// Startup
require_once(DIR_SYSTEM . 'startup.php');

// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');

// Registry
$registry = new Registry();

// Database 
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

// Request
$request = new Request();
$registry->set('request', $request);

// Session
$session = new Session();
$registry->set('session', $session);  		


// My stuff Below -------
$customer = new Customer($registry);  
$logged = $customer->isLogged();
$firstName = $customer->getFirstName();

if (!$logged) {
	echo "You must be logged in to view this page! Please Register or Login!";
} else {
	echo $firstName." is logged in";
}

?>
I pasted the entire index.php file from opencart then cut out the bit that outputs the site. I then just create an instance of the Customer class and got the data from that.
I've then bit by bit cut out all the code that seemed not to be needed. and the above is the least i can get it down to without any errors or warning showing up.
I hope this will be of use to others.
If anyone can see a mistake or if there is something important I've removed, please let me know.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by Avvici » Thu Jul 19, 2012 1:07 pm

Just remember the rule of thumb is that a session must be started somewhere. Once it's started it must be re-declared every time you want to add a session variable, id, or what not so yes it would take constant access to Open Cart's session_start()

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC
Who is online

Users browsing this forum: No registered users and 22 guests