0

I've got a site hosted with Heroku. Heroku assigns my site a domain name of someName.herokuapp.com. I've got a custom domain name www.someName.com which points to someName.herokuapp.com. For consistency purposes in my config file I have a variable:

$ServerPath = "somename.herokuapp.com/";

That way when I need to reference a some file I could just go $ServerPath.$fileName

Here's the problem. When the user logs in from www.somename.com a session is created on the server. However if at any time the user clicks some link which is tied to $ServerPath the user is redirected to somename.herokuapp.com and on THAT domain the session seems to be non-existant and the user is logged out.

Is there any way to keep my $ServerPath var as someName.herokuapp.com and have the session to be open on both www.someName.com and someName.herokuapp.com?

Allen S
  • 3,471
  • 4
  • 34
  • 46

2 Answers2

0

Unfortunately, this is the expected behavior for (session) cookies. You request a certain domain and the browser will send it's cookies for that domain (i.e. www.somename.com). Now you click a link: somename.herokuapp.com. The browser does not send ANY cookie from www.somename.com

There are 2 possible solutions:

  1. automaticly redirect somename.herokuapp.com to www.somename.com (or visa versa), so everything is always on the same (sub)domain.

  2. Create a session-transfer via the URL. You could use session.use-trans-sid or anything similar. See http://www.php.net/manual/en/session.configuration.php#ini.session.use-trans-sid. This approach also has downsides.

Ronald Swets
  • 1,669
  • 10
  • 16
0

You can redirect user using .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://www.someName.com [R=301,L]

He will be redirected from url's other than http://www.someName.com

Sean Doe
  • 277
  • 2
  • 9