The MU forums have moved to WordPress.org

User logged in cookie (12 posts)

  1. kunal17
    Member
    Posted 14 years ago #

    I am trying to create some integration between a jobberbase script install and WPMU/buddypress members. In other words, I want only members of my WPMU/buddypress community to be able to post jobs on the jobberbase page.

    One way someone suggest I should do this is to look for any cookie generated when a member is logged into the community and only then let them access the job post page otherwise redirect them to the buddypress signup/login page.

    I would like to know:
    How would I access and use the necessary cookie?
    Could anyone help with the code I would need to use? I am not very familiar with php

    Thanks for your help!

  2. cafespain
    Member
    Posted 14 years ago #

    To be honest, if you're not very familiar with PHP, then you are not going to get very far with this.

    Look at the link below for hints on getting WPMU and Buddypress sharing a login cooke, then make a note of the cookie name you are setting up and that will be the one you need to use:

    http://umwblogs.org/wiki/index.php/Integrating_WPMu%2C_BuddyPress%2C_and_bbPress#Integrating_bbPress_with_WPMu

  3. kunal17
    Member
    Posted 14 years ago #

    Thanks cafespain, Ill do my best.

  4. kunal17
    Member
    Posted 14 years ago #

    Like cafespain said, I am stumped as to how to solve this problem. I have come across snippets of code that people have tried on different applications but I cannot understand how to implement in my situation and unfortunately I do not have any budget to hire someone to do it :(.

    Any further help will be greatly appreciated. Thanks.

  5. kunal17
    Member
    Posted 14 years ago #

    One way that I have seen people using wordpress authorization in other applications is by adding the following code to the header of the external page:

    include_once('../wp-config.php');

    to be able to use wordpress functions like is_user_logged_in in the external page.

    However, when I include the above code into the external page, it redirects me to wp-signup.php.

    Please help. I feel that I am close to getting this done but I need some advice.

  6. kunal17
    Member
    Posted 14 years ago #

    Just thought I would mention, WPMU is installed in the root folder and the external page is in a subfolder.

  7. cafespain
    Member
    Posted 14 years ago #

    Ok, a different tack :)
    If you have firefox, go into the preferences and clear all your cookies. then go to your site and login.

    Now when you look at the cookies in your browser you will see those created by WordPress. These are the ones you need to look for. One will be labelled wordpress_logged_in_ followed by a lot of mess.

    This is your logged in cooke. Have a look at its contents and you will see something like: admin%mess%moremess

    The first part is the username that is logged in. So with this in mind in PHP you can do the following:

    $mycookie = $_COOKIE['wordpress_logged_in_mess'];
    $splitcookie = explode('%', $mycookie);
    $username = $splitcookie[0];

    Barebones, and could maybe do with a check to see if cookie exists first, that the username is valid and the rest of the cookie authenticates (think there is a function in pluggable.php that does that). But that's one approach.

  8. pumpkinpatch
    Member
    Posted 14 years ago #

    ...and to help you find the cookies or manipulate them, you could use a FireFox Add-on:
    https://addons.mozilla.org/en-US/firefox/addon/60
    Web Developer->Cookies->View Cookie Information
    You can view all domain cookies, delete selected ones etc.

  9. kunal17
    Member
    Posted 14 years ago #

    cafespain,

    Thanks. Your method is definitely smarter than pulling all the wordpress function files in.

    Infact, to get things started, I am even happy with just checking if the 'wordpress_logged_in' cookie exists (this would classify the visitor as a member no?) and then allowing access to the external page. I know this is probably not a secure way to do things but it should be enough for now.

    Im going to look around to find a function that can check if the cookie exists. Btw, using the addon recommended by pumpkinpatch(thanks!) I see that the cookie name is wordpress_logged_in_. Would this be all I need to check for?

  10. kunal17
    Member
    Posted 14 years ago #

    To clarify my last question,

    what I mean is that when I use 'isset($_COOKIE[“cookiename”])' do I just put 'wordpress_logged_in_' for the cookiename or as you mentioned above 'wordpress_logged_in_mess'?

    If I have to use the second, how do I set the 'mess' part (will it not be different for every user)?

    I tried using just 'wordpress_logged_in_' as the cookie name but it did not recognize it even though I was logged in.

    Thanks!

  11. pumpkinpatch
    Member
    Posted 14 years ago #

    Each cookie will have a name and an associated value --> Check to see if the value is set. Example:
    Cookie Name: wordpress_logged_in_8cddkfjdfdfkjdfjkfkdfjkdfjk
    Cookie Value: admin%jfds898435kjngnkfdgkjfgfdr9tretlkfdmkfdl

  12. cafespain
    Member
    Posted 14 years ago #

    Were the 'mess' part of my code is, you should replace it with whatever your cookie has called itself. As pumpkinpatch shows in his post, the bit at the end is a mess of characters (which is why I shortened it to mess).

    If this cookie exists and has a value then the user is, technically, logged in to WordPress (MU).

    So you could use:

    if(!empty($_COOKIE['wordpress_logged_in_8cddkfjdfdfkjdfjkfkdfjkdfjk']) {
    //I'm logged in
    }

    the empty function would check if a) the cookie exists and b) there is a value for it.

About this Topic

  • Started 14 years ago by kunal17
  • Latest reply from cafespain