Programmable admin connection magento not working

I want to programmatically register a user for magento admin. The admin page is in an iframe and should automatically be redirected to the admin control panel without authentication. I used the code found in an ancient post and it matches the magento core source. Code:

umask(0);
$app = Mage::app('default');

Mage::getSingleton('core/session', array('name' => 'adminhtml'));

// supply username
$user = Mage::getModel('core/factory')->getModel('admin/user')->loadByUsername($loginadmin);

  if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
         Mage::getSingleton('adminhtml/url')->renewSecretUrls();
  }

  $session = Mage::getSingleton('admin/session');
  $session->setIsFirstVisit(false);
  $session->setUser($user);
  $session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
  Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));

  if ($session->isLoggedIn()) {
      //Redirection vers le dashboard
       $url = "index.php/admico/dashboard";
       header('Location: '.$url);
  }

When I have var_dump()data, the user exists and has all the information, such as firstname, id, etc., and all this is correct. The code is included in the latter ifand redirected to "index.php / admico / dashboard", therefore it is $sessioncorrectly registered. But in any case, the connection form is displayed on the first page, as if the session was not registered and not the admin control panel.

- , ?

+6
2

, , iframe -. , PHP header. , , SID URL. :

$SID=$session->getEncryptedSessionId();
$url = "index.php/admico/dashboard?SID=" . $SID;

, PHP setcookie() $session , . . , . , this , -, . !

0

, firefox, safari chrome. cookie , .

test.php

<iframe src="http://localhost.site/test_login.php" width="100%"></iframe>

test_login.php

<?php

require 'app/Mage.php';

umask ( 0 );
Mage::app ( 'admin' );

Mage::getSingleton('core/session', array('name' => 'adminhtml'));

// supply username
$user = Mage::getModel('admin/user')->loadByUsername("USERNAME");

if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
    Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}

$session = Mage::getSingleton('admin/session');
$session->setIsFirstVisit(false);
$session->setUser($user);
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
Mage::dispatchEvent('admin_session_user_login_success',array('user'=>$user));

if ($session->isLoggedIn()) {
    //Redirection vers le dashboard
    $url = "/admin/dashboard/";
    header('Location: '.$url);
}
0

All Articles