LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2014, 11:42 AM   #1
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Rep: Reputation: Disabled
php session not working in chrome and IE but working fine in Firefox


I have php session not working in chrome and IE but working fine in Firefox. I'm getting this error in page4.: it show variable empty in page4, session not passing in page4 after the user click click me in page3

Notice: Undefined index: username in /var/www/html/phptest/test4.php on line 5

Please see my code and let me know where the error is.

Page2

<html>
<body>
<form action="test3.php" method="post">
Username: <br><input type="text" name="username"></br>
<input type="submit" name = 'submit1' value= 'Login'>
</form>
</body>
</html>
Page3

<html>
<body>

<?php
session_start();
$username = $_POST['username'];
$_SESSION['username']= $_POST['username'];
echo "<br> Hi $username.</br>";
?>

<form action="test4.php" method="post">
<input type="submit" name = 'submit' value= 'click me'>
</form>

</body>
</html>
Page 4

<?php
session_start();
$username = $_SESSION['username'];
echo "<br> Hi $username.</br>";
?>
 
Old 06-04-2014, 12:57 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Are you starting at Page2 with each browser?
 
Old 06-04-2014, 04:21 PM   #3
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
yes im starting with page2.php
 
Old 06-04-2014, 06:17 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
It works for me in all three browsers.
 
Old 06-04-2014, 07:37 PM   #5
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
then whats wrong in my system, can you help me to fix it.
 
Old 06-04-2014, 09:37 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
I'm not sure. I copied your code verbatim and it worked.
As stated make sure you start at page2 in each browser. Session variables are not common between browsers.
 
Old 06-05-2014, 06:17 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
However, if cookies are not enabled in IE or Chrome then sessions will not work as your code is written.
 
Old 06-05-2014, 11:35 AM   #8
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
i can see session file being created but its empty. any idea why
 
Old 06-06-2014, 07:55 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,647
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Sure ... the session cookies aren't being returned by the browser. The session-store has been created, the cookie has been sent, but it never comes back.

Activate the debugging facilities on Chrome and IE on the client side, and w-a-t-c-h the exchanges. You should see the host returning a set-cookie: request, and you should see the cookie value being stored. You should then see a request being sent to the same URL (note that "secure" and "non-secure" connections are distinct!), and the cookie-value should accompany it in the header.

"Guessing" is patently-useless. Look.
 
Old 06-06-2014, 10:12 AM   #10
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
i have figure out what exactly the problem is.
session_id(); not passing the same id number to the second page in result session file are created empty. Browser like IE and Chrome are not able to pick up session variable.

but not able to fix it.
any help regard this.
 
Old 06-06-2014, 11:11 AM   #11
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
sundialsvcs, i ran IE debugging i can see set-cookie being store in /tmp folder, also i can see only received cookie, not send.
 
Old 06-08-2014, 09:59 AM   #12
hadinetcat
LQ Newbie
 
Registered: Mar 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
Problem solved I had to change session.cookie_path in php.ini to / instead /tmp.
Thank you.
 
Old 06-08-2014, 10:08 AM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Great, you can mark the thread as solved via the thread tools menu at the top of the page.
 
  


Reply

Tags
php, php5



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No SCIM input in Terminal or in Emacs but working fine in Firefox / Thunderbird rlx Slackware 1 04-08-2014 03:24 PM
Skype working | Firefox Chrome Not Working saurabh113 Linux - Networking 1 11-29-2011 04:05 PM
Flash pages working in chrome but not in firefox StefanP Linux - Software 7 08-23-2011 12:58 AM
[SOLVED] php session not working famsinyi Programming 5 04-22-2011 09:20 AM
PHP script through cron not working fine. vikasumit Linux - General 5 09-04-2008 02:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration