Magento Integration With T-Hub - php

am setting up a sand box for a T-Hub Integration with Magento and quickbooks. I've set my life site up locally using WAMP server, and now Its on to trying to tie that local Magento site into T-hub.
The first error that I received stated the
"Connection to Magento store failed. Service authentication failure - Notice: Undefined index: httponly in c:\wamp\www\testsite\appcode\core\mage\Core\Model\Session\Abtract\Varien.php on line 98."
After some searching I found the the general consensus on that one was I had to put an ssl on my local server, done, that problem's gone. Now I'm get a general error message that simply says "Connection to Magento Failed"
I used the test page that atandra included with their files which returned this:
<RESPONSE Version="4.1">
<Envelope>
<Command>GETORDERS</Command>
<StatusCode>9001</StatusCode>
<StatusMessage>
Service authentication failure - Warning: array_key_exists() expects parameter 2 to be array, string given in C:\wamp\www\adamsarms\app\code\core\Mage\Captcha\Model\Observer.php on line 166
</StatusMessage>
<Provider>Magento</Provider>
</Envelope>
</RESPONSE>
Which kicks back to this is the php file:
public function checkUserLoginBackend($observer)
{
$formId = 'backend_login';
$captchaModel = Mage::helper('captcha')->getCaptcha($formId);
$loginParams = Mage::app()->getRequest()->getPost('login', array());
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
if ($captchaModel->isRequired($login)) {
if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
$captchaModel->logAttempt($login);
Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
}
}
$captchaModel->logAttempt($login);
return $this;
}
This line is the one it directly points to:
$login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
I'm not sure which direction I need to go to fix this error to make t-hub start talking to magento proper, I've included everything that I've got, if someone needs more information please let me know, I just need a better understanding of what might be causing this error to possibly find a path to fixing it.

This is an issue with a Legacy codebase with the T-Hub extension. It was created for PHP 5.3 & Magento versions 1.4 & below. They really should update this thing since people are using it.
The companies official response is this: http://support4.atandra.com/index.php?/Knowledgebase/Article/View/92/4/magento-array_key_exists-error
Which is horrible because it relies on overriding core files.
What's going on is Mage_Captcha_Model_Observer has an event checkUserLoginBackend() that gets fired. This expects the POST info for 'login' to be a certain format. This is something that has changed over the years since legacy code does not have it in this format.
This is a really hacky fix. But it's better than overriding core magento files.
Change the CheckUser() function of Mage/Thub/Model/Run/Run.php to this (I've removed some of their comments):
public function CheckUser()
{
try {
$username = $this->RequestParams['USERID'];
$password = $this->RequestParams['PASSWORD'];
//here we just set the POST to our specified format..
//which is what the observer model thinks it should be
Mage::app()->getRequest()->setPost('login', array(
'username' => $username,
'password' => $password
));
$user = Mage::getSingleton('admin/user');
$userRole = Mage::getSingleton('admin/role');
if ($user->authenticate($username, $password)) {
$loadRole = $userRole->load($user->getRoles($user));
} else {
print($this->xmlErrorResponse($this->RequestParams['COMMAND'], '9000',
'Order download service authentication failure - Login/Password supplied did not match', $this->STORE_NAME, ''));
exit;
}
} catch (Exception $e) {
$this->Msg[] = "Critical Error CheckUser (Exception e)=" . $e->getMessage(); //BB 11Nov2014
print($this->xmlErrorResponse($this->RequestParams['COMMAND'], '9001',
'Service authentication failure - ' . " " . $e->getMessage(), $this->STORE_NAME, ''));
// End - <TIBB> 13Dec2011
exit;
}
}
Another alternative is to extend the Mage_Captcha_Model_Observer class with your own version that removes those array checks in checkUserLoginBackend().

Related

Error while importing Quickbook library in Laravel 5.3

I am integrating quickbooks with my laravel app. After integration I got this error,
PHP Warning: require_once(../QuickBooks.php): failed to open stream:
No such file or directory in
/home/vipin/projects/development/Quickbook/config/app.php on line 2
PHP Fatal error: require_once(): Failed opening required '../QuickBooks.php'
(include_path='.:/usr/share/php:/home/ubuntu/projects/development/Quickbook/vendor/consolibyte/quickbooks')
in /home/ubuntu/projects/development/Quickbook/config/app.php on line
2
Here is my controller Quickbook.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
// require_once '../QuickBooks.php';
use App\Http\Requests;
class QuickBooksController extends Controller
{
private $IntuitAnywhere;
private $context;
private $realm;
public function __construct(){
if (!\QuickBooks_Utilities::initialized(env('QBO_DSN'))) {
// Initialize creates the neccessary database schema for queueing up requests and logging
\QuickBooks_Utilities::initialize(env('QBO_DSN'));
}
$this->IntuitAnywhere = new \QuickBooks_IPP_IntuitAnywhere(env('QBO_DSN'), env('QBO_ENCRYPTION_KEY'), env('QBO_OAUTH_CONSUMER_KEY'), env('QBO_CONSUMER_SECRET'), env('QBO_OAUTH_URL'), env('QBO_SUCCESS_URL'));
}
public function qboConnect(){
if ($this->IntuitAnywhere->check(env('QBO_USERNAME'), env('QBO_TENANT')) && $this->IntuitAnywhere->test(env('QBO_USERNAME'), env('QBO_TENANT'))) {
// Set up the IPP instance
$IPP = new \QuickBooks_IPP(env('QBO_DSN'));
// Get our OAuth credentials from the database
$creds = $this->IntuitAnywhere->load(env('QBO_USERNAME'), env('QBO_TENANT'));
// Tell the framework to load some data from the OAuth store
$IPP->authMode(
\QuickBooks_IPP::AUTHMODE_OAUTH,
env('QBO_USERNAME'),
$creds);
if (env('QBO_SANDBOX')) {
// Turn on sandbox mode/URLs
$IPP->sandbox(true);
}
// This is our current realm
$this->realm = $creds['qb_realm'];
// Load the OAuth information from the database
$this->context = $IPP->context();
return true;
} else {
return false;
}
}
public function qboOauth(){
if ($this->IntuitAnywhere->handle(env('QBO_USERNAME'), env('QBO_TENANT')))
{
; // The user has been connected, and will be redirected to QBO_SUCCESS_URL automatically.
}
else
{
// If this happens, something went wrong with the OAuth handshake
die('Oh no, something bad happened: ' . $this->IntuitAnywhere->errorNumber() . ': ' . $this->IntuitAnywhere->errorMessage());
}
}
public function qboSuccess(){
return view('qbo_success');
}
public function qboDisconnect(){
$this->IntuitAnywhere->disconnect(env('QBO_USERNAME'), env('QBO_TENANT'),true);
return redirect()->intended("/yourpath");// afer disconnect redirect where you want
}
public function createCustomer(){
$CustomerService = new \QuickBooks_IPP_Service_Customer();
$Customer = new \QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Ms');
$Customer->setGivenName('Shannon');
$Customer->setMiddleName('B');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Shannon B Palmer ' . mt_rand(0, 1000));
// Terms (e.g. Net 30, etc.)
$Customer->setSalesTermRef(4);
// Phone #
$PrimaryPhone = new \QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);
// Mobile #
$Mobile = new \QuickBooks_IPP_Object_Mobile();
$Mobile->setFreeFormNumber('860-532-0089');
$Customer->setMobile($Mobile);
// Fax #
$Fax = new \QuickBooks_IPP_Object_Fax();
$Fax->setFreeFormNumber('860-532-0089');
$Customer->setFax($Fax);
// Bill address
$BillAddr = new \QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);
// Email
$PrimaryEmailAddr = new \QuickBooks_IPP_Object_PrimaryEmailAddr();
$PrimaryEmailAddr->setAddress('support#consolibyte.com');
$Customer->setPrimaryEmailAddr($PrimaryEmailAddr);
if ($resp = $CustomerService->add($this->context, $this->realm, $Customer))
{
//print('Our new customer ID is: [' . $resp . '] (name "' . $Customer->getDisplayName() . '")');
//return $resp;
//echo $resp;exit;
//$resp = str_replace('{','',$resp);
//$resp = str_replace('}','',$resp);
//$resp = abs($resp);
return $this->getId($resp);
}
else
{
//echo 'Not Added qbo';
print($CustomerService->lastError($this->context));
}
}
public function addItem(){
$ItemService = new \QuickBooks_IPP_Service_Item();
$Item = new \QuickBooks_IPP_Object_Item();
$Item->setName('My Item');
$Item->setType('Inventory');
$Item->setIncomeAccountRef('53');
if ($resp = $ItemService->add($this->context, $this->realm, $Item))
{
return $this->getId($resp);
}
else
{
print($ItemService->lastError($this->context));
}
}
public function addInvoice($invoiceArray,$itemArray,$customerRef){
$InvoiceService = new \QuickBooks_IPP_Service_Invoice();
$Invoice = new \QuickBooks_IPP_Object_Invoice();
$Invoice = new QuickBooks_IPP_Object_Invoice();
$Invoice->setDocNumber('WEB' . mt_rand(0, 10000));
$Invoice->setTxnDate('2013-10-11');
$Line = new QuickBooks_IPP_Object_Line();
$Line->setDetailType('SalesItemLineDetail');
$Line->setAmount(12.95 * 2);
$Line->setDescription('Test description goes here.');
$SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
$SalesItemLineDetail->setItemRef('8');
$SalesItemLineDetail->setUnitPrice(12.95);
$SalesItemLineDetail->setQty(2);
$Line->addSalesItemLineDetail($SalesItemLineDetail);
$Invoice->addLine($Line);
$Invoice->setCustomerRef('67');
if ($resp = $InvoiceService->add($this->context, $this->realm, $Invoice))
{
return $this->getId($resp);
}
else
{
print($InvoiceService->lastError());
}
}
public function getId($resp){
$resp = str_replace('{','',$resp);
$resp = str_replace('}','',$resp);
$resp = abs($resp);
return $resp;
}
}
Config/app.php
<?php
require_once '../QuickBooks.php';
return [
'qbo_token' => env('QUICKBOOK_TOKEN'),
'qbo_consumer_key' => env('QBO_OAUTH_CONSUMER_KEY'),
'qbo_consumer_secret' => env('QBO_CONSUMER_SECRET'),
'qbo_sandbox' => env('QBO_SANDBOX'),
'qbo_encryption_key' => env('QBO_ENCRYPTION_KEY'),
'qbo_username' => env('QBO_USERNAME'),
'qbo_tenant' => env('QBO_TENANT'),
'qbo_auth_url' => 'http://app.localhost:8000/qbo/oauth',
'qbo_success_url' => 'http://app.localhost:8000/qbo/success',
'qbo_mysql_connection' => 'mysqli://'. env('DB_USERNAME') .':'. env('DB_PASSWORD') .'#'. env('DB_HOST') .'/'. env('DB_DATABASE'),
There are several areas to improve on here with the given code & approach.
As Anton correctly points out, you should not be directly requiring any of the quickbooks library files. If you've loaded this in via Composer then they will be automatically loaded because the Composer autoloader will load the QuickBooks file from the vendor. This is correct for Laravel as well as general Composer-based applications - the only difference with Laravel is that there isn't a specific Laravel Package ServiceProvider that's been written for this SDK, but that doesn't matter.
The QuickBooks library tries to jump on top of autoloading any class that starts with 'QuickBooks', so you're better off making a QuickBooks folder for your controller class. This is more of a 'gotcha' and has been pointed out in the repo issues.
The reason you're getting the Driver/.php error is because you have not specified your QBO_DSN, or have done so incorrectly - this DSN environment variable that you're passing to the initialisation is being run through parse_url() in the SDK code, coming up false or null and breaking the auto-loader for initalisation. If this was set to a proper connection string (e.g. mysqli://username:password#host:port/database and note that port must be a number or it's considered malformed), it would correctly process the DSN and continue to load the page. Be aware that initialisation will attempt to parse and fetch the network address of the host, so you can't just put a dummy value in there and expect it to work - this needs to exist first.
You're mixing your environment variables and application configuration, without using either of them properly. If you wanted your DB connection string (a.k.a. QBO_DSN) to be constructed a particular way into the application configuration setting qbo_mysql_connection, then you should be using the configuration setting when trying to initialise/load/etc. Instead of using env('QBO_DSN'), you should be using config('app.qbo_mysql_connection') to load the constructed version from your app settings. Typically you would not be loading so many environment variables into a controller at all - that should be handled by the application, and then the controller calling the application configuration so it's agnostic of how they were defined.
You shouldn't need to require anything from inside the app configuration file either - that file is just for configuration variables being set up.
Since the QuickBooks SDK isn't properly namespaced (yet), there isn't a nice PSR-4 way of loading (and use-ing) the classes, but it's still good practice to use use clauses at the top of the file (e.g. use QuickBooks_Utilities;) so that you can use the classes without fear of forgetting the preceding backslash (i.e. no more \QuickBooks_Utilities, just QuickBooks_Utilities in usage) - there are several instances in the given code where this has been forgotten, and will not work because the Laravel application is namespaced and will look for those classes in the App\Http\Controllers namespace (e.g. errors like "Cannot find class App\Http\Controllers\QuickBooks_Utilities").
Indentation - pick a style (e.g. tabs, 2-space, PSR-2, etc) and then stick to it. Run phpcs or some other clean-up tool over all of your code before committing to your repository or posting on SO - readability is important!
Using require instead of autoloader is a bad practice in modern frameworks (and generally in modern PHP). I highly recommend using the package manager (eg composer) to properly add modules to the project.
For example, to add a quickbooks library into the project using composer, you need to run only one command:
composer require consolibyte/quickbooks
Add this line in footer of Config/app.php
require_once '../QuickBooks.php';

CakePHP3 - Custom page error 404 not working

I doing tutorial follow http://book.cakephp.org/3.0/en/development/errors.html#exception-renderer but it is not working and display blank page.
In config/bootstrap.php
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();
In src/Error/AppError.php
<?php
namespace App\Error;
use Cake\Error\BaseErrorHandler;
class AppError extends BaseErrorHandler
{
public function _displayError($error, $debug)
{
return 'There has been an error!';
}
public function _displayException($exception)
{
return 'There has been an exception!';
}
public function handleFatalError($code, $description, $file, $line)
{
return 'A fatal error has happened';
}
}
I create my_error.ctp in src/Template/Layout/my_error.ctp. And in my src/Template/Error/error404.ctp I change layout to my_error.ctp.
$this->layout = 'my_error';
Finally, In my controller
use Cake\Network\Exception\NotFoundException;
$staff = $this->Staff->find()->where(['Staff.StaffId = '=> $id, 'Staff.PartnerId = ' =>$this->partnerId])->first();
if (empty($staff)) {
throw new NotFoundException(__('Staff not found'));
}
Whenever encountering blank pages, enabled debug mode, visit the URL again, and check your error logs.
However, problem in this case is most likely that the docs are incorrect/misleading, as the example app error won't do anything at all. The _ prefixed methods are ment to be protected, having them return something has no effect, and handleFatalError is ment to return a boolean.
Just look at the source of Cake\Error\BaseErrorHandler and the core error handler Cake\Error\ErrorHandler, the methods that you are overwriting are ment to generate output!
You may want to report that as an issue over at GitHub.
If all you want to do, is create a custom 4xx error page, then all you need to do is to edit the src/Template/Error/error400.ctp template accordingly.
I found my mistake. :(
Because in bootstrap.php I copy below code at the end of file. Therefore Cake cannot understand it. Please close this issue. Thank you for support.
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();

How to connect with OpenFire(xmpp) using RESTAPI plugin And PHP

I am using OpenFire to manage my xmpp server I want to add new users using a PHP, So I have installed RESETAPI Plugin to OpenFire to administrate with http request. I am using gidkom Project also. But getting a error
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\IM\registration.php on line 12
My code for registration.php is:
<?php
if(isset($_POST["User_Name"]) && isset($_POST["Name"]) )
{
$User_ID = $_POST["User_Name"];
$User_Name = $_POST["Name"];
$User_Email = $_POST["Email"];
include "Gidkom/OpenFireRestApi/OpenFireRestApi.php";
// Create the OpenfireUserservice object
$api = new Gidkom\OpenFireRestApi
// Set the required config parameters
$api->secret = "my keys";
$api->host = "domain.my.org";
$api->port = "9090"; // default 9090
// Optional parameters (showing default values)
$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1"; // plugin
// Add a new user to OpenFire and add to a group
$result = $api->addUser($User_ID, 'Password', $User_Name, $User_Email, array('welcome'));
// Check result if command is succesful
if($result['status']) {
// Display result, and check if it's an error or correct response
echo 'Success: ';
echo $result['message'];
} else {
// Something went wrong, probably connection issues
echo 'Error: ';
echo $result['message'];
}
//Add to roster
$api->addToRoster('Administrator', 'admin');
}
else
{
echo 'Error: Something went wrong..... please go back ';
}
I want the page to add a new new user in the openfire and add admin to his roster.
Thanks !!!!
Semicolon is missing.
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;
The errors were caused because of an outdated version of PHP, YPdating PHP to latest version fixed it...
prerequirements: must to have composer.exe installed on your machine
from cmd.exe
go to your web root server(htdocs) then
go into your directory which contain the rest api sources
then from this cmd.exe(or create one batch)
c:/..../....> composer install
Remark: -this commnad(composer install) must to have in same directory the composer.json
-this command(composer install) will create one subdirectory "vendor" named
now into your index.php must insert on top, the following line:
<?php
include "vendor/autoload.php";
....
and continue your actual program
and is trully must to end the lines with ;
...
?
https://github.com/gnello/php-openfire-restapi
Easy Php REST API Client for the Openfire REST API Plugin which provides the ability to manage Openfire instance by sending an REST/HTTP request to the server
Please read documentation for further information on using this application.
Installation
composer require gnello/php-openfire-restapi
Authentication
There are two ways to authenticate:
Basic HTTP Authentication
$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_user', 'your_password');
Shared secret key
$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_secret_key');
Start
$api = new \Gnello\OpenFireRestAPI\API('your_host', 9090, $authenticationToken);
Users
//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', 'email#domain.com', $properties);
//Delete a user
$result = $api->Users()->deleteUser('Username');
//Ban a user
$result = $api->Users()->lockoutUser('Username');
//Unban a user
$result = $api->Users()->unlockUser('Username');
Open Link Fore more.

Web Service - PHP Zend ( Blank Page - No Errors )

I made a simple version of my code. It gives no errors, but it simply doesn't work.
(I have Soap enabled for PHP)
Class With Function: (Metodo.php)
class Teste {
/*
* #return string
*/
function SayHello() {
return "Hello, WORLD";
}
}
Server: (Server.php)
<?php
require_once('Metodo.php');
if($_SERVER['QUERY_STRING'] == "wsdl") {
try {
require_once('Zend/Soap/AutoDiscover.php');
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('Teste');
$wsdl->handle();
}catch(exception $e) {
echo $e->getMessage();
}
} else {
$wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);
require_once('Zend/Soap/Server.php');
$server = new SoapServer($wsdl_url);
$server->setClass('Teste');
$server->handle();
}
?>
Client: (Client.php)
<?php
require_once('Zend/Soap/Client.php');
$wsdl_url = "http://localhost:8090/WebService/Server.php?wsdl";
$client = new Zend_Soap_Client($wsdl_url);
try {
echo $client->SayHello();
echo ":)";
} catch (SoapFault $e) {
echo $e->getMessage();
}
?>
It just prints ":)", no errors, but it won't call the method SayHello().
If anyone would PLEASE help me, I would be so thankful. Really.
Thank you so much.
A few things:
$server = new SoapServer($wsdl_url);
should be:
$server = new Zend_Soap_Server($wsdl_url);
it may work without, but since you required in the Zend Soap Server class on the line before, you may as well use it.
In Server.php:
$wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);
make sure that this URL includes the right port (as you are using port 8090). I can't remember off the top of my head if HTTP_HOST does or not.
And then most importantly, in your class:
/*
* #return string
*/
function SayHello() {
return "Hello, WORLD";
}
should be:
/**
* #return string
*/
function SayHello() {
return "Hello, WORLD";
}
note the extra * at the start of the comment. The auto discovery classes work using PHPDoc blocks, which must start with /** in order to be valid. (Easy to miss!)
If it still doesn't work after these changes, make absolutely sure that PHP has not cached your bad WSDL file (PHP caches WSDL files by default). The easiest way to do this is to remove any files that start with 'wsdl' from your /tmp/ folder (or equivalent on your system). After making these changes I got the right output using your code.
There should be an error being logged someplace. Check the server and PHP logs. There are also some 'trace/debug' settings for the SOAP client. You might get more info back on last call/response with those enabled.
With out more info here are some observations:
non standard function name. In ZF camelCase is the norm.
non standard port, not sure why but might be related
Have you tried with the a browser to access the WSDL? Does it resolve?
freenodes' #zftalk channel (IRC) can be a good resource as well. Please post back here if you do find an answer there.

Two (almost) identical pieces of code produce separate results

I have been working on a little MVC project to assist in my self-learning and I have come across an issue that completely baffled me. I made a blog section in this MVC-ish system and pulled user permissions from an ACL with no problem whatsoever.
I moved onto creating a member section and as soon as i added any permissions checking I get the following error from Chrome:
No data received
Unable to load the web page because the server sent no data.
Here are some suggestions:
Reload this web page later.
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
I thought it was weird, so I double checked my error logs and nothing had shown up. So I decided to copy and paste the working blog code into the member file, reloaded and i got the EXACT same error, the only difference between the two files right now is the file name and the class name.
Here is the Blog code:
<?php
class blog extends frontController {
public $model;
public $user;
public function __construct()
{
parent::__construct();
$this->model = $this->autoload_model();
$this->user = $this->load_user();
$this->user->getUserRoles();
}
public function index()
{
//Will only list the latest post ;)
if(!$this->user->hasPermission('blog_access'))
{
$array = $this->model->list_posts();
if(empty($array))
{
$this->variables(array(
'site_title' => 'View Blog Posts',
'post_title' => 'Sorry but there are no posts to display'
));
} else {
$this->variables(array(
'site_title' => 'View Blog Posts',
'list' => $array[0],
'post_title' => $array[0]['entry_title'],
'link' => str_replace(' ', '_',$array[0]['entry_title']),
));
}
} else {
$this->variables(array(
'site_title' => 'Error :: Design Develop Realize',
'body' => 'Sorry, but you do not have permission to access this',
));
}
$this->parse('blog/list', $this->toParse);
}
This is the member file:
<?php
class member extends frontController {
public $model;
public $user;
public function __construct()
{
parent::__construct();
$this->model = $this->autoload_model();
$this->user = $this->load_user();
$this->user->getUserRoles();
}
public function index()
{
//Will only list the latest post ;)
if(!$this->user->hasPermission('blog_access'))
{
//$array = $this->model->list_posts();
if(empty($array))
{
$this->variables(array(
'site_title' => 'Design Develop Realize :: View Blog Posts',
'post_title' => 'Sorry but there are no posts to display'
));
} else {
$this->variables(array(
'site_title' => 'Design Develop Realize :: View Blog Posts',
'list' => $array[0],
'post_title' => $array[0]['entry_title'],
'link' => str_replace(' ', '_',$array[0]['entry_title']),
));
}
} else {
$this->variables(array(
'site_title' => 'Error :: Design Develop Realize',
'body' => 'Sorry, but you do not have permission to access this',
));
}
$this->parse('blog/list', $this->toParse);
}
In the member class, if I comment out $this->user = $this->load_user(); then the error disappears!!!
Just for reference here is that function:
protected function load_user()
{
if(!$this->loader->loaded['acl'])
{
$this->loader->loadCore('acl');
}
return $this->loader->loaded['acl'];
}
Any help or suggestions would be appreciated as I am stumped!
PS yes I do have error reporting set to cover everything and no it does not log anything!
EDIT: Because all files go through index.php I have placed the error reporting there:
<?php
error_reporting(E_ALL);
ini_set('date.timezone', "Europe/London");
require_once('system/library/loader.php');
$loader = new loader();
$loader->loadCore(array('frontController', 'routing'));
EDIT 2: loadCore() is below
public function loadCore($toLoad, $params = false)
{
//important task first, check if it is more then 1 or not
if(is_array($toLoad))
{
//more then one so lets go to the task!
foreach($toLoad as $file)
{
if(file_exists('system/library/' . $file . '.php'))
{
require_once('system/library/' . $file . '.php');
if($params)
{
$this->loaded[$file] = new $file($params);
} else {
$this->loaded[$file] = new $file;
}
} else {
trigger_error("Core File $file does not exist");
}
}
} else {
//Phew, less work, it is only one!
if(file_exists('system/library/' . $toLoad . '.php'))
{
require_once('system/library/' . $toLoad . '.php');
if($params)
{
echo(__LINE__); exit;
$this->loaded[$toLoad] = new $toLoad($params);
} else {
$this->loaded[$toLoad] = new $toLoad;
}
}
}
}
Update: I modified loadCore so that if it was the acl being called it would use a try...catch() and that has not helped as it will not display an error just the same chrome and IE pages
Update 2: I have spoken with my host and it seems that everytime this error occurs, apache logs the following (not sure why I cannot see it in my copy of the logs!)
[Wed Feb 22 08:07:11 2012] [error] [client 93.97.245.13] Premature end
of script headers: index.php
You have commented out
//$array = $this->model->list_posts();
So now array is null and you are trying to use
'list' => $array[0],
'post_title' => $array[0]['entry_title'],
which definitely will generate an error.
EDIT:-
I see you have
'body' => 'Sorry, but you do not have permission to access this' , )); }
That is in second else which is a syntax error. and generates an output. If you have enabled, compress output in CI, that will cause this error.
"Premature end of script headers" are internal server errors. Which generally occurs when script breaks and does not send any HTTP headers before send the error messages. There might be several causes to this.
One might be output buffering. May be the server you are using buffers the output by default. I will suggest turning off the output_buffering using output_buffering = off on php.ini [docs here].
Make sure you are sending correct HTTP headers also
print "Content-type: text/html\n\n";
There are few more suggestion on this link.
To learn more about this error, go here.
Hope it helps
I'd be interested in seeing what's inside the loadCore function.
Have you used error_log anywhere? It might help shed some light on the issue.
Have you tested this page in different browsers? Googled your error, and it's indicating that it may be chrome specific?
Your statement that commenting out the loadCore('acl') is interesting, so obviously I would start there. You're sure that it is getting the system/library/acl.php page via the loader? Aka, it is triggering that line 2 below the exit in loadCore()? var_dump the return imo to make sure you're getting the object.
First of all. This error is produced when your server disconnect before it send any data.
A few suggestions.
your code is broken and let crash the application
your error logging should be enhanced by NOTICES
write tests to check every part
u should enable and use a debugger (zend_debugger, xdebug)
post a few more connection infos (e.g. wget -O - --debug 'url')
There is/was a special chrome issue for that problem
http://www.google.pl/support/forum/p/Chrome/thread?tid=3aa7b40eb01a95c8&hl=en#fid_3aa7b40eb01a95c80004ae797939c267
I suggest checking whether there are any blank lines before the tags.
What file names are you using?, are there any conventions you have to follow to fit a framework you might be using?
I wonder if this is a server problem and not a code problem?
This thread suggests that the server error you are seeing (500 premature end to headers) could be the result of Apache logs that are too full and need to be rotated. However it really could be anything - it seems to suggest simply that the script returns no output at all to the browser.
The other thing I'd check is file permissions, and the functioning of the include_once and file_exists in the loadCore method, as that looks the likeliest area to cause problems that might stop the script without even throwing a php error.
Maybe it´s a character/encoding error, open both files with notepad++ , goto Encoding, then select Convert to UTF-8, save the file and test it again.
Good Luck!

Categories