0

I am trying to access an admin routed url from a frontend routed URL using curl. I do the following:

            $ch = curl_init();
            curl_setopt ($ch, CURLOPT_URL, 'http://site.com/index.php/admin/mycache/verify/');
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
            curl_setopt ($ch, CURLOPT_COOKIE, $_COOKIE['adminhtml']);
            $Verify = curl_exec($ch);
            curl_close($ch);
            echo "V: $Verify";

The idea here is that I want that url to return a 1 if the user is logged into the admin part of my site, and anything else otherwise. When I do the above though, even though the adminhtml cookie is set, curl never gets the data from that URL. Can someone explain why and/or how to fix that?

1

You can try following -

$sesId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false ;
$session = false;
if($sesId){
    $session = Mage::getSingleton('core/resource_session')->read($sesId);
}
$loggedIn = false;
if($session)
{
    if(stristr($session,'Mage_Admin_Model_User'))
    {
        $loggedIn = true;
    }
}
var_dump($loggedIn);

This will be true if admin logged in and false if not. Hope this will help you.

  • Does "Mage::getSingleton('core/resource_session')->read($sesId);" only return a session if there is a real session and not just a spoofed cookie? – user2045 Aug 30 '13 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.