Hi,
i need help with cookie when changing domain name of third level.....

<?
$value="10";
if ($ok=1)setcookie("Test14", $value, time()+30);
?>

works only in the domain where i arrive.....

<?
$value="10";
if ($ok=1)setcookie("Test14", $value, time()+30, "", "a.dev", 0);

?>

works for the domain i have put but i want that if i show

echo "<br>COOKIE14=".$_COOKIE["Test14"];

it show also from domain b.dev

so definitifly i want something like that:

<?
$value="10";
if ($ok=1)setcookie("Test14", $value, time()+30, "", ".dev", 0);
echo "<br>COOKIE14=".$_COOKIE["Test14"];
?>

first time i go on

http://a.dev/index.php?ok=1

and it write the cookie......if i refresh or i then go to

http://a.dev

it show the content of the cookie

then also if i go on the

http://b.dev

i want the cookie be readable and so it show the content......

Any help?

    you need to set the cookie domain to your main domain.
    setcookie params:
    string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]]
    so for yourdomain.com
    setcookie($cookiename, $cookievalue, $expiry, "/", "yourdomain.com");
    this will be visible on both a.yourdomain.com and b.yourdomain.com

    http://www.php.net/setcookie

      Because i have done all my stuff with sessions.....using session_register() and want to extend all variables to the same a.sito.dev and b.sito.dev i have find something like that that can help me:

      session_set_cookie_params(0 , '/directory/',".sito.dev");

      before call session_start();

      but don' t work.....

        okuto1973 wrote:

        Because i have done all my stuff with sessions.....using session_register() and want to extend all variables to the same a.sito.dev and b.sito.dev i have find something like that that can help me:

        session_set_cookie_params(0 , '/directory/',".sito.dev");

        before call session_start();

        but don' t work.....

        no no, sorry you misunderstood me.
        check here the parameters for setcookie:
        http://au2.php.net/setcookie

        what you need is to set the
        path to '/' and
        domain to 'sito.dev'

        in your setcookie statement.

        Edit:
        so the setcookie command from your code which was:
        setcookie("Test14", $value, time()+30, "", "a.dev", 0);
        will be:
        setcookie("Test14", $value, time()+30, "/", "sito.dev", 0);

          OK....
          but that's for cookie , stored in hard client but now i have something new, that i have find in some topic that work but i don't.

          If i have

          session_start();

          if ($username!="" && $password!="")
          {

          $sess_username=$username;
          $sess_password=$password;

          session_registered(sess_username);
          session_registered(sess_password);

          $seelct="SELECT id,nome,cognome from utenti where username='$sess_username' and password='$sess_password'";

          $db_query_programmi=mysql_db_query($db_name,$select);
          if ($db_query_programmi!="")$numero=mysql_num_rows($db_query_programmi);
          if ($numero==0)
          {
          $sess_username="";
          $sess_password="";
          header("Location: password_errata.php");
          exit();
          }
          else
          {
          $nome=mysql_result($db_query_programmi,0,"nome");
          $cognome=mysql_result($db_query_programmi,0,"cognome");

          $loggato=1;

          }

          }

          If i move from www.sito.dev to a.sito.dev a new session is created with different id number and the variables are empty....only if i return to www.sito.dev then the page identify me becouse the variables are set to the session id of www.sito.dev

            Same thing again mate.
            The session is usually using cookies to identify.

            Your session is started to a certain domain, you need to set the session domain to your top domain, sito.dev.

            see the documentation of the session cookie params:
            www.php.net/session-set-cookie-params

              4 months later

              session_set_cookie_params(0 , '',".sito.it");

              before the start_session()

              works if together with a httaccess correctly set to the directory where .sito.it is set to go.

              Now i want that also another www.sito2.it redirect to the same directory and so an alias works fine but when i change from this site to the .sito.it the session became different cause for the browser-server the client go to another web pages.........

              How to write another specific domain name to be accepted?
              Tried with

              session_set_cookie_params(0 , '',".sito.it,www.sito2.it");

              and many other sim like but don't works.......

                Write a Reply...