0

I am new to laravel and coding for 2 two weeks now and stuck in an deployment problem.

My local machine: Windows 10 with PHP Storm, MySql and I am running on artisan serve On Production it runs on https://www.trim.finance

My Issue is that on local everything works within my program status but live i get the TOKEN Missmatch Error because my Session Key is rewritten every REQUEST. Local the Session looks ok with old Data and the previuos link and so on but live there is just the KEY.

Maybe this is helpful. On Strato i force the website to run on HTTPS an LOCAL i don't because i don't know how i will artisan demand that.

I tried the last days to get it running but don't have a clou. I inserted a button on the end to show session->all() and routet it at /session.

my Shame i uploaded the env File on produktion server to make both more similar.

.env File on Server

APP_ENV=local
APP_LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=**
DB_PORT=3306
DB_DATABASE=**
DB_USERNAME=**
DB_PASSWORD=**

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=mailgun
MAIL_DOMAIN=https://api.**
MAIL_SECRET=key-**

config/app.php on Server

return [
'name' => env('APP_NAME', 'tRIM'),
'env' => env('APP_ENV', 'local'),
'debug' => env('APP_DEBUG', true),
'url' => env('APP_URL', 'https://www.trim.finance'),
'timezone' => 'Europe/Berlin',
'locale' => 'en',
'fallback_locale' => 'de',
'key' => env('APP_KEY', 'base64:KEYCODE'),
'cipher' => 'AES-256-CBC',
'log' => env('APP_LOG', 'single'),
]

config/session.php on Server

return [
'driver' => env('SESSION_DRIVER', 'database'),
'lifetime' => 60000,
'expire_on_close' => false,
'encrypt' => true,
'files' => storage_path('framework/sessions'),
'connection' => 'mysql',
'table' => 'sessions',
'store' => null,
'lottery' => [2, 100],
'cookie' => 'trim_session',
'path' => '/',
'domain' => null,
'secure' => env('SESSION_SECURE_COOKIE', true),
'http_only' => false,
];

Test1: Please try to Register /register to see the Problem. (Every data is fake so feel free to try).

Test2: Try to create a new Adress /create

My debbugging got me so far

  1. The issue ist just on the produktion side. (I allready deleted the hole webServer and copied all data again to see if there is something missing oder online changed.) local it works.

  2. Every get request doen't need the session so no harm.

    • BUT i inserted an SESSION button to see the data and every refresh of the page makes a new session [_token"]
  3. EveryPost request don't geht through because of the TokenMismatchException.

    • I edited the TokenMismatchException what is matched and every time he generates a new Session _token
    • I shortcuted the Token comparison and did'nt get through because Laravels safety features.

Forms are generated with blade like {{Form:model}} or {{Form:open}} which generated

<input type="hidden" name="_token" value="S1d...">

Sessions are stored in the Database for every request one line .. seems too much.. every Session one line it should be. Here an Example from my database. I generated it from Artisan session:table

I did just a refresh on the website.

| id | user_id | ip_address | user_agent | payload | last_activity | | bf4QOHxQAMvrTgGw0PfidIKmHd0hRrAt86FPVYWz | NULL | 2a02:8109:a40:2f20:403d:806a:5818:dbf3 | Mozilla/5.0... | ZXlKcGRpSTZJblV3UkhoY... | 1501147035|

| I0sg8K8zvSQS1a1vN2OOTYnKVnsVJQP3kv4ZxtqT | NULL | 2a02:8109:a40:2f20:403d:806a:5818:dbf3 | Mozilla/5.0... | ZXlKcGRpSTZJbE5WYkVOT... | 1501146839 |

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • are you using csrf_field ? – Naincy Jul 27 '17 at 10:46
  • **Edited** my POST: Yes in my own Forms and definitly in `php artisan make:auth` generated Forms. :-) – Rainer Flessner Jul 27 '17 at 11:03
  • [Arikel](https://stackoverflow.com/questions/42292283/laravel-tokenmismatchexception-database-session/45340647#45340647) I read this articel may it bee a problem with colum length in my database? `create table sessions ( id varchar(255) not null, user_id int(10) unsigned null, ip_address varchar(45) null, user_agent text null, payload text not null, last_activity int not null, constraint sessions_id_unique unique (id) )` leads in my case to varchar(191) When you hit the limit. Set the following. INNODB utf8 VARCHAR(255) INNODB utf8mb4 VARCHAR(191) – Rainer Flessner Jul 27 '17 at 11:15

0 Answers0