HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Pass a custom profile field in the URL

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#45962 (In Topic #10052)
Avatar

Fan in training

I am developig a web based application and i would like to link it to OCP. Is there a way of passing someting like user id to my application from OCP? What i mean is i should know the OCP user name and show only his/her data in my application.

I am using the URL link from the comcode pages.

Back to the top
 
Posted
Rating:
#45965
Avatar

Hi,

That could be quite tricky, depending how well you want to do it.

The easiest way is to cheat a bit by making two assumptions:
  • That a user will always reach the ocPortal site first (which will establish a login session)
  • That the user has cookies enabled

Then you'll be able to read the session cookie, and look this up the corresponding member ID in ocPortal's sessions table. You don't need to use any ocPortal code at all, just read the database directly using whatever code you like (e.g. mysql_query).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#45966
Avatar

Is there a way of passing someting like user id to my application from OCP?

Actually if you want to make things even easier and can make one additional assumption:
  • It doesn't need to be secure

Then you can just pass it in as a URL parameter. Just put ?uid={$USER} on the end of your like!


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#45970
Avatar

Fan in training

Hi Chris,

Thanks for the help.

But, i seem to be having problems with both the solutions. if i use, ?uid={$user}, i am always getting uid as 2, no matter under which user name i am logged in. i kept loggin out and in and different users, but $USER was always 2.

when i tried using the php function session_id(), i couldn't get the id of the session started by OCP. I am getting a different session id.

Any way out?
Back to the top
 
Posted
Rating:
#45972
Avatar

But, i seem to be having problems with both the solutions. if i use, ?uid={$user}, i am always getting uid as 2, no matter under which user name i am logged in.

Whoops. I forgot that URLs aren't Tempcode/cache-safe like that.
You might need to do something like:

Code

[html]<a href="http://blahblah/?[/html]{$USER}[html]">this is a link</a>[/html]

when i tried using the php function session_id(), i couldn't get the id of the session started by OCP. I am getting a different session id.

ocPortal doesn't use PHP sessions (as the PHP session extension could be off on some servers). We store our own session cookie. Use a browser that has a decent 'View cookies' tool (Firefox with Web Developers Toolbar has one) and see what the cookies are called. Then in your code read that cookie. If the code sees the cookie isn't set I'd suggest redirecting automatically to the ocPortal site (as the user probably accessed from their bookmarks and has no session).


Last edit: by Chris Graham


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#45992
Avatar

Fan in training

Thanks Chris!

The ocp session cookie solution worked.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: