Session without www and www php

Asked

Viewed 60 times

2

Hello,

I’m having a problem, it happens that the user log in to www.meusite.com.br page his session is not in meusite.com.br, because it has this difference of without www and with www?

Can someone help me?

I’m setting the session normally

session_start();

2 answers

1

Specify a directory where both can save the session. To do this, use session_save_path(). Take a look at the documentation, the syntax would look something like this:

    <?php 
    ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
    session_start();
?>
  • It didn’t work, I put it like you wrote

  • check if the /.. /Session path is correct, if the directory does not exist, create a

1


It’s about the domain. Some domains are natively your site.com.br or www.seusite.com.br .

Try setting up your hosting CNAME. Some Dnss should point to different places. Consequently generating different sessions.

  • And how do I do that? In Cpanel, I went to Advanced Zone Editor, and there’s like:

  • Type Name TTL CNAME:

  • See if you can find an option called @A name

  • You don’t have that @A name

  • If your domain company doesn’t give you much choice of DNS configuration, try the Wallace member solution below.

  • If it doesn’t work, try a forced domain forwarding by htacces. Or set your PHP algorithm to not accept unwanted URL sessions. There are PHP functions for url capture. But I would try htacces.

  • I did by htacess same forced url

  • I’m glad it worked. Paste here the htacces configuration so that future members with the same problem may have an idea of how to solve.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.