vercel-community / php

🐘 PHP Runtime for ▲ Vercel Serverless Functions (support 7.4-8.3)

Home Page:https://php.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to enable php session

areaboy opened this issue · comments

Here is my vercel.json file


{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.6.0"
    }
  },
  "routes": [
    { "src": "/api/(.*)",  "dest": "/index.php" }
  ]
}

here is my session script
api/session1.php

<?php
  
session_start();
$_SESSION['user'] = 'Ann Cooler';
  
?>

api/session2.php

<?php
  
session_start();
echo $_SESSION['user'];
  
?>

The session is not working at all

Hi @areaboy. It's a feature, when you request your different lambdas they have different user space. You can imagine them like different docker containers. You need to use some shared space, for example redis, if you need multiple lambdas. Or you can use one lambda (one index.php) and require different session.php file according routes.

Thanks for getting back to me. Please do you have a php sample code and vercel.json sample configuration. Am New to Vercel. Thanks

I have encouter this issue before but I end up using databse as session driver. just need to provide your db credential and SESSION_DRIVER=database is fine

How would I go about doing that? I'm very new to php and Vercel so I don't fully understand where to write that. Thank you

@Transyfor the place for me to put db credential and SESSION_DRIVER=database is file .env at the root directory