Note that there are some explanatory texts on larger screens.

plurals
  1. POcookie created using jQuery(view) not accessible in php(controller) on first attempt
    text
    copied!<p>I am facing a weird problem on Chrome and Firefox, for a change it works fine IE. [<strong>Edit1</strong>: Problem occurs at times with IE also]</p> <p><strong>Premise:</strong></p> <ul> <li>In my homepageView.php, I create a cookie using jQuery, say Cookie1. </li> <li>My homepage has link to an application, lets call it App1.</li> <li>Cookie1 is accessed in App1's controller and if not found it redirects back to the homepage.</li> </ul> <p><strong>Problem Statement</strong></p> <ul> <li>Clear cache</li> <li>Go to homepage(Cookie1 is created)</li> <li>Click on link to App1.</li> <li>App1 is redirected to homepage(App1 could not access Cookie1)</li> <li>Click on App1 link <strong>again</strong>, App1 works fine.</li> </ul> <p><strong>Snippet</strong></p> <p><em>homepageView.php</em></p> <pre><code> createCookie('loggedin_ind', true); function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else{ var expires = ""; } document.cookie = name+"="+value+expires+"; path=/"; } </code></pre> <p><em>App1Contoller.php</em></p> <pre><code>function index() { if(isset($_COOKIE["loggedin_ind"])) { //Display App1 } else { redirect('http://localhost/Sitename'); } } </code></pre> <p>Can anyone please suggest why the cookie is not being writter(by jQuery) <strong>or</strong> not being read(by php) in the first occasion only? It works fine from the second time.</p> <p>It also works fine on my localhost, the problem occurs only when the code is migrated to the server.</p> <p><strong>Edit2:</strong> I replaced the <em>cookie</em> logic with <strong>sessions</strong>, but the problem persists.</p> <p><strong>Edit3:</strong> I have a strong feeling this is a <strong>server related issues</strong>. I hosted the same piece of code on my hostgator shared hosting and it works fine there, the issue only occurs on my godaddy VDS. Can anyone suggest how do I check if cookies/sessions are being handled differently on both my servers. Thanks.</p> <p>Any help is highly appreciated.Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload