Body: <blockquote>
    <p>We can't load the requested web page. This page requires cookies to be
    enabled in your browser settings. Please check this setting and enable
    cookies (if they are not enabled). Then try again. If this error
    persists, contact the site administrator for assistance.<br />Site Administrators: This error may indicate that users are
    accessing this page using a domain or URL other than the configured
    Base URL. EXAMPLE: Base URL is <a href="http://example.org" rel="nofollow noreferrer">http://example.org</a>, but some users are
    accessing the page via <a href="http://www.example.org" rel="nofollow noreferrer">http://www.example.org</a> or a domain alias like
    <a href="http://myotherexample.org" rel="nofollow noreferrer">http://myotherexample.org</a>.<br /><br />Error type: Could not find a
    valid session key.</p>
  </blockquote>
  
  <h2>BELOW IS THE CODE RESPONSIBLE FOR THE ERROR "Error type: Could not find a valid session key"</h2>
  
  <pre><code>$update_email = civicrm_api3('Email','get', $update_email_params);
              if (isset($update_email['id']) &amp;&amp; $update_email['values'][0]['email'] !=$objectRef[$parameters['email']]){
                  $update_email_final = civicrm_api3('Email','create', [
                    'sequential'=&gt; 1,
                    'contact_id'=&gt; $custom_44_result['id'],
                    'email'     =&gt; $objectRef[$parameters['email']],
                    'is_primary'=&gt; 1,
                    'id' =&gt; $update_email['id'],
                  ]); 
  
              }
  </code></pre>
  
  <p>Above is the update email code snippet which 
  --- when placed gives error Could not find a valid session key 
  --- when removed the error vanishes and process is completed</p>
  
  <p>The complete code is as seen below</p>
  
  <pre><code>define('FirstName2','custom_47');
  define('LastName2','custom_48');
  define('Email2','custom_50');
  define('CID2','custom_49')
  add_filter( 'civicrm_post', 'alter_profiles_event', 10, 4  );
  function alter_profiles_event($op, $objectName, $objectId, &amp;$objectRef){
    if (is_user_logged_in()){
      if ($objectName == 'Profile'  &amp;&amp; ($op == 'edit' ||$op == 'create' ) &amp;&amp; isset($objectRef[FirstName1])) {
        $parameters = array(
          'first_name' =&gt; FirstName2,
          'last_name' =&gt;LastName2,
          'email' =&gt;Email2,
          'cid' =&gt; CID2,
        ); 
        civicrm_alter_family_members($objectRef,$parameters);
      }
    }
  }
  
  function civicrm_alter_family_members($objectRef,$parameters) {
     $custom_44_params = [
              'sequential' =&gt; 1,
              'contact_type' =&gt; "Individual",
              'first_name' =&gt; $objectRef[$parameters['first_name']],
              'last_name' =&gt; $objectRef[$parameters['last_name']],
            ];
  
            if (isset($objectRef[$parameters['cid']]) &amp;&amp; !empty($objectRef[$parameters['cid']])) {
               $custom_44_params['contact_id'] = $objectRef[$parameters['cid']];
            }
  
            $custom_44_result = civicrm_api3('Contact','create',$custom_44_params);
  
            if (!empty($objectRef[$parameters['email']])){
  
              $update_email_params = [
                'sequential'=&gt; 1,
                'contact_id'=&gt; $custom_44_result['id'],
                'is_primary'=&gt; 1,
              ];
              $update_email = civicrm_api3('Email','get', $update_email_params);
              if (isset($update_email['id']) &amp;&amp; $update_email['values'][0]['email'] !=$objectRef[$parameters['email']]){
                  $update_email_final = civicrm_api3('Email','create', [
                    'sequential'=&gt; 1,
                    'contact_id'=&gt; $custom_44_result['id'],
                    'email'     =&gt; $objectRef[$parameters['email']],
                    'is_primary'=&gt; 1,
                    'id' =&gt; $update_email['id'],
                  ]); 
  
              }
  
         }
  
  }
  </code></pre>
  
  <p>I see updating civicrm email id gives session key error.
  I also have </p>
  
  <blockquote>
    <p>CiviCRM WordPress Profile Sync</p>
  </blockquote>
  
  <p>plugin enabled.
  Even when I disabled it, the error was existent.
  So, ruled out above plugin to be causing the error.</p>
  
  <p>When above CiviCRM email is updated, it updates the Email of the Wordpress User.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T09:58:26.507Z
Comments.Text: Your code seems to contain errors, e.g. `'first_name' => FirstName2,` so I'd fix those first and repost your code when you're sure your code is error-free.
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T10:09:10.320Z
Comments.Text: Hi @ChristianWach, its not an error, Actually FirstName2 is a constant and similarly others.
Comments.UserDisplayName: harshal
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T11:10:57.777Z
Comments.Text: Okay, I thought they might be but thought I'd check.
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T11:43:59.647Z
Comments.Text: Have you tried executing the code after clearing the cache? The error seems to be from the session controller which is shown if a certain key is not found in the URL. If you're sure it errors from the above set of code, proceed by commenting a part of the above lines and check which part is causing the error.
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T11:44:36.210Z
Comments.Text: Also see https://civicrm.stackexchange.com/questions/2422/could-not-find-a-valid-session-key-unable-to-save-any-admin-forms?rq=1
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T12:14:01.710Z
Comments.Text: Hi @jitendra-fuzion, I have checked it and he code snippet at the top is the code which gives the error ,so If i comment that it does not show the "error type: could not find a valid session key"
Comments.UserDisplayName: harshal
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T13:25:16.720Z
Comments.Text: From what I see the whole code depends on the top section, i.e, `civicrm_alter_family_members()` won't be called until you keep the `alter_profiles_event()` function. Can you update the question with the section that is responsible for the error?
Comments.UserDisplayName: jitendra - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T14:42:57.693Z
Comments.Text: Hi @jitendra-fuzion, I have highlighted the code responsible for the error, let me know if you need further clarification?
Comments.UserDisplayName: harshal
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T15:31:32.640Z
Comments.Text: @harshal I think what both of us are asking is for you to publish code that can be tested. What you have posted is a snippet of your code out of context - so much so that I assumed it had bugs. Can you rewrite the code so that others can test that it does indeed demonstrate the problem? We have no idea what your constants contain, for example. Remember: if someone can reproduce your problem, they can help.
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-19T18:40:43.660Z
Comments.Text: Hi @ChristianWach I have added the constant values at top of code.
Comments.UserDisplayName: harshal
Tags: <wordpress>
Title: Error type: Could not find a valid session key
ThreadText: # Error type: Could not find a valid session key
  
  (Asked by: username_0 on 2018-10-19)
  
  > We can't load the requested web page. This page requires cookies to be
  > enabled in your browser settings. Please check this setting and enable
  > cookies (if they are not enabled). Then try again. If this error
  > persists, contact the site administrator for assistance.  
  > Site Administrators: This error may indicate that users are
  > accessing this page using a domain or URL other than the configured
  > Base URL. EXAMPLE: Base URL is <http://example.org>, but some users are
  > accessing the page via <http://www.example.org> or a domain alias like
  > <http://myotherexample.org>.  
  >   
  > Error type: Could not find a
  > valid session key.
  
  ## BELOW IS THE CODE RESPONSIBLE FOR THE ERROR "Error type: Could not find a valid session key"
  
  ```
  $update_email = civicrm_api3('Email','get', $update_email_params);
              if (isset($update_email['id']) && $update_email['values'][0]['email'] !=$objectRef[$parameters['email']]){
                  $update_email_final = civicrm_api3('Email','create', [
                    'sequential'=> 1,
                    'contact_id'=> $custom_44_result['id'],
                    'email'     => $objectRef[$parameters['email']],
                    'is_primary'=> 1,
                    'id' => $update_email['id'],
                  ]); 
  
              }
  
  ```
  
  Above is the update email code snippet which
  --- when placed gives error Could not find a valid session key
  --- when removed the error vanishes and process is completed
  
  The complete code is as seen below
  
  ```
  define('FirstName2','custom_47');
  define('LastName2','custom_48');
  define('Email2','custom_50');
  define('CID2','custom_49')
  add_filter( 'civicrm_post', 'alter_profiles_event', 10, 4  );
  function alter_profiles_event($op, $objectName, $objectId, &$objectRef){
    if (is_user_logged_in()){
      if ($objectName == 'Profile'  && ($op == 'edit' ||$op == 'create' ) && isset($objectRef[FirstName1])) {
        $parameters = array(
          'first_name' => FirstName2,
          'last_name' =>LastName2,
          'email' =>Email2,
          'cid' => CID2,
        ); 
        civicrm_alter_family_members($objectRef,$parameters);
      }
    }
  }
  
  function civicrm_alter_family_members($objectRef,$parameters) {
     $custom_44_params = [
              'sequential' => 1,
              'contact_type' => "Individual",
              'first_name' => $objectRef[$parameters['first_name']],
              'last_name' => $objectRef[$parameters['last_name']],
            ];
  
            if (isset($objectRef[$parameters['cid']]) && !empty($objectRef[$parameters['cid']])) {
               $custom_44_params['contact_id'] = $objectRef[$parameters['cid']];
            }
  
            $custom_44_result = civicrm_api3('Contact','create',$custom_44_params);
  
            if (!empty($objectRef[$parameters['email']])){
  
              $update_email_params = [
                'sequential'=> 1,
                'contact_id'=> $custom_44_result['id'],
                'is_primary'=> 1,
              ];
              $update_email = civicrm_api3('Email','get', $update_email_params);
              if (isset($update_email['id']) && $update_email['values'][0]['email'] !=$objectRef[$parameters['email']]){
                  $update_email_final = civicrm_api3('Email','create', [
                    'sequential'=> 1,
                    'contact_id'=> $custom_44_result['id'],
                    'email'     => $objectRef[$parameters['email']],
                    'is_primary'=> 1,
                    'id' => $update_email['id'],
                  ]); 
  
              }
  
         }
  
  }
  
  ```
  
  I see updating civicrm email id gives session key error.
  I also have
  
  > CiviCRM WordPress Profile Sync
  
  plugin enabled.
  Even when I disabled it, the error was existent.
  So, ruled out above plugin to be causing the error.
  
  When above CiviCRM email is updated, it updates the Email of the Wordpress User.
  
  **Tags:** wordpress
  
  > **Comments:**
  > **username_1**: Your code seems to contain errors, e.g. `'first_name' => FirstName2,` so I'd fix those first and repost your code when you're sure your code is error-free.  
  > **username_0**: Hi @username_1, its not an error, Actually FirstName2 is a constant and similarly others.  
  > **username_1**: Okay, I thought they might be but thought I'd check.  
  > **username_2**: Have you tried executing the code after clearing the cache? The error seems to be from the session controller which is shown if a certain key is not found in the URL. If you're sure it errors from the above set of code, proceed by commenting a part of the above lines and check which part is causing the error.  
  > **username_2**: Also see https://civicrm.stackexchange.com/questions/2422/could-not-find-a-valid-session-key-unable-to-save-any-admin-forms?rq=1  
  > **username_0**: Hi @username_2, I have checked it and he code snippet at the top is the code which gives the error ,so If i comment that it does not show the "error type: could not find a valid session key"  
  > **username_2**: From what I see the whole code depends on the top section, i.e, `civicrm_alter_family_members()` won't be called until you keep the `alter_profiles_event()` function. Can you update the question with the section that is responsible for the error?  
  > **username_0**: Hi @username_2, I have highlighted the code responsible for the error, let me know if you need further clarification?  
  > **username_1**: @username_0 I think what both of us are asking is for you to publish code that can be tested. What you have posted is a snippet of your code out of context - so much so that I assumed it had bugs. Can you rewrite the code so that others can test that it does indeed demonstrate the problem? We have no idea what your constants contain, for example. Remember: if someone can reproduce your problem, they can help.  
  > **username_0**: Hi @username_1 I have added the constant values at top of code.  
  
  ---
  
  ## 0 answers
  
  