image icon indicating copy to clipboard operation
image copied to clipboard

Undefined index: _sf2_meta

Open mouhsinelonly opened this issue 12 years ago • 14 comments

i'm getting this error when using Laravel 5 ,i hope for a fix soon

mouhsinelonly avatar Oct 13 '14 09:10 mouhsinelonly

People on the Laracasts forum reported better info on this issue.

https://laracasts.com/discuss/channels/general-discussion/l5-intervention-image

If you set up a route for imagecaching, the session cookie is disabled, by setting the driver to array for this route.

$app['config']->set('session.driver', 'array');

This works in Laravel 4 but for some reason causes an error, with the current Laravel 5 development version.

ErrorException (E_UNKNOWN) Undefined index: _sf2_meta

I don't know if this is a bug in Laravel or if Intervention Image needs to adapt to Laravel 5.

Because Laravel 5 is still in development, I will wait until I know if any action is required.

olivervogel avatar Oct 15 '14 16:10 olivervogel

If you comment out the line regarding the session driver, it does work. So folks can do this until another solution is available.

jmfleming avatar Oct 15 '14 16:10 jmfleming

I am still getting this error, the solution by jmfleming works, but I have to manually do it each time I run composer update...

philmarc avatar Mar 14 '15 17:03 philmarc

@PhilMarc You can use this in Laravel without using the service provider. Changed to this awhile back and works the same. It does change the code a bit though, which is the only downside. Does allow you to composer update and not worry about blowing the fix away.

jmfleming avatar Mar 16 '15 11:03 jmfleming

as @jmfleming mentioned, after commenting out the line: https://github.com/Intervention/image/blob/master/src/Intervention/Image/ImageServiceProviderLaravel5.php#L88

The url based images seem to work as expected again (it seemed to break after moving to L5).

atmediauk avatar Mar 18 '15 13:03 atmediauk

I had no problems with this line in Laravel 5.

$app['config']->set('session.driver', 'array');

But another session cookie for XSRF-TOKEN is set anyway, so session cookies are not completely disabled for the route and the setting makes no sense. Hence I removed the line in 8f3761154b4c1f5128365dfc32cbf757f27d97b6 for now. At least until I can figure out a way, how to disable session cookies completely for a certain route from a ServiceProvider.

olivervogel avatar Mar 18 '15 17:03 olivervogel

Thanks, appreciate that. I don't think their is a simple way to unset middleware in a package. Most people suggest manually removing from the global kernel array which isn't ideal.

I'm not sure if it helps but I am using Laravel 5 in conjunction with Platform by Cartalyst (https://cartalyst.com/).

Thanks again

atmediauk avatar Mar 19 '15 11:03 atmediauk

Still getting this error :cry:

carlosflorencio avatar May 13 '15 15:05 carlosflorencio

Still getting this error

baribadamshin avatar Jun 04 '15 23:06 baribadamshin

I am also getting this error...

RobinMalfait avatar Jun 05 '15 07:06 RobinMalfait

Make sure you are on the newest version. The problematic line should no longer be present in /src/Intervention/Image/ImageServiceProviderLaravel5.php.

// should be gone
$app['config']->set('session.driver', 'array');

olivervogel avatar Jun 05 '15 17:06 olivervogel

Still getting this error..

andriytkachiv avatar Jul 12 '15 18:07 andriytkachiv

for me the problem was in Illuminate\Session\Store.php on line 286, so I changed from this:

foreach (array_merge($this->bags, [$this->metaBag]) as $bag) {
       $this->put($bag->getStorageKey(), $this->bagData[$bag->getStorageKey()]);
}

to this:

 foreach (array_merge($this->bags, [$this->metaBag]) as $bag) {
       if(isset($this->bagData[$bag->getStorageKey()])){
         $this->put($bag->getStorageKey(), $this->bagData[$bag->getStorageKey()]);
       }
 }


MladenJanjetovic avatar Aug 01 '15 14:08 MladenJanjetovic

This can be solved by

 config()->set('session.driver', null);

rather than editing core.

Also, can remove the CSRF token by overriding the handle method and adding a bit of additional logic. The shouldPassThrough method simply checks if the route is in except (existing functionality), so just skip adding cookie to the response in those scenarios:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
use Closure;
use Illuminate\Session\TokenMismatchException;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'results/upload/upload.php'
    ];

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     *
     * @throws \Illuminate\Session\TokenMismatchException
     */
    public function handle($request, Closure $next)
    {
        if ($this->isReading($request) || $this->shouldPassThrough($request) || $this->tokensMatch($request)) {
            if(!$this->shouldPassThrough($request))
                return $this->addCookieToResponse($request, $next($request));
            return $next($request);
        }

        throw new TokenMismatchException;
    }
}

ogrethegreat avatar Aug 24 '15 22:08 ogrethegreat