LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-23-2021, 02:31 AM   #1
piyushpatelia
LQ Newbie
 
Registered: Feb 2021
Posts: 3

Rep: Reputation: Disabled
Session is not working


Hi,

While i am trying to fetch session in next page, i couldn't get it.

Here is the code:

Page 1:
ob_start();session_start();
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
echo '<br /><a href="bbb.php?' . SID . '">page 2</a>';

Page 2:
ob_start();session_start();
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat


it's display null value. also two session files generated in session.path folder.
 
Old 02-23-2021, 04:16 AM   #2
captain_sensible
Member
 
Registered: Apr 2010
Posts: 352

Rep: Reputation: 145Reputation: 145
<?php
session_start();

session_start should be the first line (and by its self) in a php file
 
Old 02-23-2021, 04:48 AM   #3
piyushpatelia
LQ Newbie
 
Registered: Feb 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
i have keep that first only but still couldn't get anything. also i am trying to fetch pages through IP. is there anything which i need to change in php.ini or httpd.conf file?

here is my httpd.config file code:

AddType text/CSS .css
AddHandler text/css .css
#Header set Set-Cookie HttpOnly;Secure
#RequestHeader append Cookie " foo=bar HttpOnly;Secure"
#Header set Set-Cookie HttpOnly;Secure
#Header edit set-cookie ^(.*)$ $1;httponly;secure
#Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

<IfModule security2_module>
#SecRuleEngine on
#ServerSignature Off
#ServerTokens Prod
</IfModule>
 
Old 02-23-2021, 07:52 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
What linux distribution/version are you running?
Have you installed php?

Here is one complete example for code you are trying to run.

Page1.php
Code:
 <?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>
<br> <a href="page2.php">page 2</a>
</body>
</html>
Page2.php
Code:
 <?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Echo session variables that were set on previous page
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
?>

</body>
</html>
 
Old 02-23-2021, 08:03 AM   #5
piyushpatelia
LQ Newbie
 
Registered: Feb 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
we have commented Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure code in security.conf file and it's working fine
 
  


Reply



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
Unable to launch "cinnamon-session-cinnamon" X session "cinnamon-session-cinnamon" -found; Falling back to default "session." xxxindigo Linux Mint 22 09-01-2019 09:21 AM
My Samsung notebook n150 display unable to display "cinnamon-session-cinnamon" not found; falling back to default session Gastoneciacci Linux - Laptop and Netbook 1 04-28-2018 11:25 AM
Session key renegotiation if session lasts longer than configured (e.g. an hour) then session keys needs to be renegotiated. dakshinya Linux - Newbie 1 02-04-2016 04:15 PM
php session not working in chrome and IE but working fine in Firefox hadinetcat Programming 12 06-08-2014 10:08 AM
add a session to Session of gdm freenet Linux - Software 0 08-07-2003 05:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:19 PM.

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