Jump to content

Accessing $ccUserData for use in an additional script


RetroRocker

Recommended Posts

Hi

I searched on this topic within CC3 forums and found a couple of threads which were really unresolved. So ...

If I have an additional script containing HTML form elements such as textboxes, how can I access the $ccUserData in order to populate those elements for an already logged in / registered user without that user having to input their details again ?

I have discovered the definition of $ccUserData in includes/session.inc.php and that individual elements can be extracted along the lines of $ccUserData[0]['firstName'] and so on but I don't seem to be able to pass those elements to my own additional script.

I've tried, for example, creating a new global variable in includes/global.inc.php and ensuring that this script is included in my script, then assigning an element of $ccUserData to that global variable ... but my variable is always empty.

Has anybody achieved this ? ... if so, could you let me know how you did it ? or if it's not been done before (that would be surprising) ... how to go about it ?

my thanks in advance

RR

Link to comment
Share on other sites

Hi

I have done another 'all forums' search on this topic but apart from some related threads, still can't find anything really concrete or more ideas. I have never yet managed to extract any data from $ccUserData. Any element I try eg. $ccUserData[0]['whatever'] is always empty. I really would be grateful for any help with this ... deadline's approaching :)

thanks

RR

Link to comment
Share on other sites

In your new script (a whole new "file" as opposed to adding a function or routine to an existing file, right?), have you set the file includes properly?

The easiest way to do this is to rely on index.php and tell index what feature group you want to use:

// START MAIN CONTENT

if(isset($_GET['act'])){

These text boxes... where are they? That is, one what feature page? ViewCat, ViewDoc, ViewProd?

Link to comment
Share on other sites

Hi

Thanks for posting about this, it's appreciated. Please let me clarify...

Yes, this is a whole new file. All I am trying to do here is to access a customer's profile data (which I believe to be held in the $ccUserData[0] array for any user currently logged in for a given session). Then, for example, I simply want to echo elements of that data in 'myscript.php' ... nothing more than that.

I have so far made some progress with this by using the following code (with includes) posted elsewhere in this forum ie. (http://forums.cubecart.com/index.php?showtopic=9343&hl=$ccUserData). This, with a little manipulation, does work fairly well but for one thing ... that is, if a user is logged in and then myscript.php is called, it appears that they get logged out. Could this be something to do with instantiating a new db object ?

However, this only happens once ! If you then log in again and call myscript.php to echo $ccUserData elements it works fine and you can then do this as many times as you like with no ill effects.

'myscript.php' is nothing more than the code in the post mentioned above with some echo statements added to display the current session's profile data as required.

Am I going about this wrongly ? ... I noticed that you have hinted at a different approach using $_GET['act']. How would I utilize this and would it be a better approach ? or stick with what I have done so far and try to find a fix for this strange initial logging out issue ?

thanks RR

Link to comment
Share on other sites

The reason I suggested index.php is because it goes through and verifies the existence of a logged-in "session" as determined by the presence of cookies that match an entry in the sessions database (I think). Once the grunt-work of verifying "logged-in"-ness is taken care of, then ccUserData should be available.

Link to comment
Share on other sites

OK, thanks ... I see your point with that. I think that the code in the forum post I gave the URL of earlier, actually starts a new session which is why you get the logout initially and then have to login again, as previously mentioned ... after which it all works.

I am uncertain how to go about using $_GET['act'] in the context I'm after but it does seem a better way to go if a current / existing session can be used. It seems like bad behaviour to log a customer out simply through calling myscript :blush: .

Please would you be kind enough to offer a few more clues as to how to access $ccUserData through the use of $_GET['act'], just where to start would be really helpful as would any suggestions. I'm getting nowhere at the moment ...

thanks RR

Link to comment
Share on other sites

In the file /index.php (the main file, into which all other features are brought), at around line 60, /includes/session.inc.php is brought in. session.inc.php's job, among other things, is to determine if any valid cookies were given to the store and, if so, see if those cookies are in the session database table. If so, then we *might* know who the visitor is if they logged in prior to this session.

If they had logged in, and the session was still valid (it could expire), we will have the customer ID number and all relevant facts about the customer.

Back at /index.php, at around line 90, starts where you can hook your custom page.

Since the store is currently displaying the "homepage" (that is, $_GET['act'] = nothing), you should not provide a link to that page until you have a logged in visitor. Even so, since 'get' is part of the URL string, one could force the including of a page not yet ready for the visitor. For example, see /includes/content/account.inc.php at around line 51. In here, this page (/skins/{your_skin}/styleTemplates/content/account.tpl) has sections that get parsed for a valid session and an invalid session. Consider coding you page to do this as well.

Since your page will be "included" via index.php's $_GET['act'] switch/case, make sure it is coded according to the method that you can see in account.inc.php. Look at other scripts and their matching .tpl files to see how, based on a decision, only certain parts of your .tpl file actually get used.

Send me a PM if you need to take this any deeper. I'll be glad to help (when I have free time every now and then).

Link to comment
Share on other sites

Thank you very much indeed for taking the time and effort to post the information above. It formed the nucleus from which I successfully accomplished my original task. It was just what I needed to point me in the right direction. :D

all the best

RetroRocker

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...