Connecting Tech Pros Worldwide Forums | Help | Site Map

Session Problems

Maximus
Guest
 
Posts: n/a
#1: Nov 18 '06
Lately, i installed WAMP server on my pc, and started coding as always.

Today, I noticed that sessions started going weird.

I declare a session in page1 for example, I echo it in page2 after a
form submission ... al goes fine ... then click a link on page2 leading
to page 3 ..... the session is no longer valid.

echoing the session gives NULL


What's wring? any help?
I am using session_start(); in all 3 pages.


Good Man
Guest
 
Posts: n/a
#2: Nov 18 '06

re: Session Problems


"Maximus" <teddy.am@gmail.comwrote in news:1163869860.838020.132370
@k70g2000cwa.googlegroups.com:
Quote:
Lately, i installed WAMP server on my pc, and started coding as always.
>
Today, I noticed that sessions started going weird.
>
I declare a session in page1 for example, I echo it in page2 after a
form submission ... al goes fine ... then click a link on page2 leading
to page 3 ..... the session is no longer valid.
>
echoing the session gives NULL
>
>
What's wring? any help?
I am using session_start(); in all 3 pages.

are you calling it properly, via $_SESSION['mysession']; and not just
expecting $mysession to exist without that?
Jerry Stuckle
Guest
 
Posts: n/a
#3: Nov 18 '06

re: Session Problems


Maximus wrote:
Quote:
Lately, i installed WAMP server on my pc, and started coding as always.
>
Today, I noticed that sessions started going weird.
>
I declare a session in page1 for example, I echo it in page2 after a
form submission ... al goes fine ... then click a link on page2 leading
to page 3 ..... the session is no longer valid.
>
echoing the session gives NULL
>
>
What's wring? any help?
I am using session_start(); in all 3 pages.
>
Are you calling session_start before ANYTHING is sent to the client?
This can include any DOCTYPE, etc. statements, or even white space.

What happens if you add the following two statements right at the
beginning of your file (before the session_start() call)?

error_reporting(E_ALL);
ini_set("display_errors","1");


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Maximus
Guest
 
Posts: n/a
#4: Nov 18 '06

re: Session Problems


The same script thats working fine online on link:
http://www.tam-sms.com is not working on my wamp server locally.

I think there's a problem with the php.ini file installed by WAMP5
server.
Jerry Stuckle wrote:
Quote:
Maximus wrote:
Quote:
Lately, i installed WAMP server on my pc, and started coding as always.

Today, I noticed that sessions started going weird.

I declare a session in page1 for example, I echo it in page2 after a
form submission ... al goes fine ... then click a link on page2 leading
to page 3 ..... the session is no longer valid.

echoing the session gives NULL


What's wring? any help?
I am using session_start(); in all 3 pages.
>
Are you calling session_start before ANYTHING is sent to the client?
This can include any DOCTYPE, etc. statements, or even white space.
>
What happens if you add the following two statements right at the
beginning of your file (before the session_start() call)?
>
error_reporting(E_ALL);
ini_set("display_errors","1");
>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jerry Stuckle
Guest
 
Posts: n/a
#5: Nov 18 '06

re: Session Problems


Maximus wrote:
Quote:
The same script thats working fine online on link:
http://www.tam-sms.com is not working on my wamp server locally.
>
I think there's a problem with the php.ini file installed by WAMP5
server.
Jerry Stuckle wrote:
>
Quote:
>>Maximus wrote:
>>
Quote:
>>>Lately, i installed WAMP server on my pc, and started coding as always.
>>>
>>>Today, I noticed that sessions started going weird.
>>>
>>>I declare a session in page1 for example, I echo it in page2 after a
>>>form submission ... al goes fine ... then click a link on page2 leading
>>>to page 3 ..... the session is no longer valid.
>>>
>>>echoing the session gives NULL
>>>
>>>
>>>What's wring? any help?
>>>I am using session_start(); in all 3 pages.
>>>
>>
>>Are you calling session_start before ANYTHING is sent to the client?
>>This can include any DOCTYPE, etc. statements, or even white space.
>>
>>What happens if you add the following two statements right at the
>>beginning of your file (before the session_start() call)?
>>
>>error_reporting(E_ALL);
>>ini_set("display_errors","1");
>>
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================
>
>
If that were the case I wouldn't expect it to work at all.

What happens if you do a

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

And what happens if you use the code I sent you earlier?

What's the actual failing code?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Maximus
Guest
 
Posts: n/a
#6: Nov 19 '06

re: Session Problems


Jerry, here's the code for the 3 pages ...


INDEX.PHP
-----------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="page1.php">
<label>
<input type="text" name="textfield" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
</body>
</html>

--------------------------
PAGE1.PHP
--------------------------
<?php

session_start();

$_SESSION['1'] = $_POST['textfield'];

echo $_SESSION['1'];

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

?>

<p>&nbsp;</p>
<p><a href="page2.php">page 2</a</p>

-----------------------------
PAGE2.PHP
-----------------------------

<?php

session_start();

$var = $_SESSION['1'];

echo $var;

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

?>

-----------------------------
Page 2 doesn't show any sessions registered.
Nothin at alll ....


Jerry Stuckle wrote:
Quote:
Maximus wrote:
Quote:
The same script thats working fine online on link:
http://www.tam-sms.com is not working on my wamp server locally.

I think there's a problem with the php.ini file installed by WAMP5
server.
Jerry Stuckle wrote:
Quote:
>Maximus wrote:
>
>>Lately, i installed WAMP server on my pc, and started coding as always.
>>
>>Today, I noticed that sessions started going weird.
>>
>>I declare a session in page1 for example, I echo it in page2 after a
>>form submission ... al goes fine ... then click a link on page2 leading
>>to page 3 ..... the session is no longer valid.
>>
>>echoing the session gives NULL
>>
>>
>>What's wring? any help?
>>I am using session_start(); in all 3 pages.
>>
>
>Are you calling session_start before ANYTHING is sent to the client?
>This can include any DOCTYPE, etc. statements, or even white space.
>
>What happens if you add the following two statements right at the
>beginning of your file (before the session_start() call)?
>
>error_reporting(E_ALL);
>ini_set("display_errors","1");
>
>
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstucklex@attglobal.net
>==================
>
If that were the case I wouldn't expect it to work at all.
>
What happens if you do a
>
echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";
>
And what happens if you use the code I sent you earlier?
>
What's the actual failing code?
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jerry Stuckle
Guest
 
Posts: n/a
#7: Nov 19 '06

re: Session Problems


Maximus wrote:
Quote:
Jerry Stuckle wrote:
>
Quote:
>>Maximus wrote:
>>
Quote:
>>>The same script thats working fine online on link:
>>>http://www.tam-sms.com is not working on my wamp server locally.
>>>
>>>I think there's a problem with the php.ini file installed by WAMP5
>>>server.
>>>Jerry Stuckle wrote:
>>>
>>>
>>>>Maximus wrote:
>>>>
>>>>
>>>>>Lately, i installed WAMP server on my pc, and started coding as always.
>>>>>
>>>>>Today, I noticed that sessions started going weird.
>>>>>
>>>>>I declare a session in page1 for example, I echo it in page2 after a
>>>>>form submission ... al goes fine ... then click a link on page2 leading
>>>>>to page 3 ..... the session is no longer valid.
>>>>>
>>>>>echoing the session gives NULL
>>>>>
>>>>>
>>>>>What's wring? any help?
>>>>>I am using session_start(); in all 3 pages.
>>>>>
>>>>
>>>>Are you calling session_start before ANYTHING is sent to the client?
>>>>This can include any DOCTYPE, etc. statements, or even white space.
>>>>
>>>>What happens if you add the following two statements right at the
>>>>beginning of your file (before the session_start() call)?
>>>>
>>>>error_reporting(E_ALL);
>>>>ini_set("display_errors","1");
>>>>
>>>>
>>>>--
>>>>==================
>>>>Remove the "x" from my email address
>>>>Jerry Stuckle
>>>>JDS Computer Training Corp.
>>>>jstucklex@attglobal.net
>>>>==================
>>>
>>>
>>If that were the case I wouldn't expect it to work at all.
>>
>>What happens if you do a
>>
>>echo "<pre>\n";
>>print_r($_SESSION);
>>echo "</pre>\n";
>>
>>And what happens if you use the code I sent you earlier?
>>
>>What's the actual failing code?
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================
>
>
Jerry, here's the code for the 3 pages ...
>
>
INDEX.PHP
-----------------
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>
</head>
>
<body>
<form id="form1" name="form1" method="post" action="page1.php">
<label>
<input type="text" name="textfield" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
</body>
</html>
>
--------------------------
PAGE1.PHP
--------------------------
<?php
>
session_start();
>
$_SESSION['1'] = $_POST['textfield'];
>
echo $_SESSION['1'];
>
echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";
>
?>
>
<p>&nbsp;</p>
<p><a href="page2.php">page 2</a</p>
>
-----------------------------
PAGE2.PHP
-----------------------------
>
<?php
>
session_start();
>
$var = $_SESSION['1'];
>
echo $var;
>
echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";
>
?>
>
-----------------------------
Page 2 doesn't show any sessions registered.
Nothin at alll ....
>
>
(Top posting fixed)

OK, are you sure there is NOTHING before the <?php in page2.php?

And what happens if you put the code I gave you immediately following
the <?php tag?

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Maximus
Guest
 
Posts: n/a
#8: Nov 19 '06

re: Session Problems


There's nothing before the <?php

and if i put the tag u gave me i get this

Array
(
)



This is the weirdest thing i ever got in PHP so far...

Jerry Stuckle
Guest
 
Posts: n/a
#9: Nov 19 '06

re: Session Problems


Maximus wrote:
Quote:
There's nothing before the <?php
>
and if i put the tag u gave me i get this
>
Array
(
)
>
>
>
This is the weirdest thing i ever got in PHP so far...
>
Sorry, this was the code I was referring to. I didn't mean to be confusing:


error_reporting(E_ALL);
ini_set("display_errors","1");

P.S. ensure you look at your page source, also.

One other thing - what does phpinfo() say for your session-related
settings? Your code should be working fine.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Jim Carlock
Guest
 
Posts: n/a
#10: Nov 19 '06

re: Session Problems


"Maximus" <teddy.am@gmail.composted:
: here's the code ...

Try the following...
<snip>
PAGE1.PHP...
<?php

session_start();

$_SESSION['1'] = $_POST['textfield'];

echo("<html>\n<head>\n<title>Test</title>\n</head>\n<body>\n");
echo("<p>$_SESSION['1']</p>\n");

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

?>

<p>&nbsp;</p>
<p><a href="page2.php">page 2</a</p>
</body></html>
</snip>

Where's the <!DOCTYPE ... >, <html>, <headand <body>
tags? And do you have your cookies turned on in your browser?

--
Jim Carlock


Maximus
Guest
 
Posts: n/a
#11: Nov 19 '06

re: Session Problems


PAGE1.PHPis working fine ...
PAGE2.PHP doesn't echo any sessions.

Sessions at that page turn to NULL.


Jim Carlock wrote:
Quote:
"Maximus" <teddy.am@gmail.composted:
: here's the code ...
>
Try the following...
<snip>
PAGE1.PHP...
<?php
>
session_start();
>
$_SESSION['1'] = $_POST['textfield'];
>
echo("<html>\n<head>\n<title>Test</title>\n</head>\n<body>\n");
echo("<p>$_SESSION['1']</p>\n");
>
echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";
>
?>
>
<p>&nbsp;</p>
<p><a href="page2.php">page 2</a</p>
</body></html>
</snip>
>
Where's the <!DOCTYPE ... >, <html>, <headand <body>
tags? And do you have your cookies turned on in your browser?
>
--
Jim Carlock
Maximus
Guest
 
Posts: n/a
#12: Nov 19 '06

re: Session Problems


Now here's something even more weird

<?
phpinfo();
?>

gives a blank white page ...


Jim Carlock wrote:
Quote:
"Maximus" <teddy.am@gmail.composted:
: here's the code ...
>
Try the following...
<snip>
PAGE1.PHP...
<?php
>
session_start();
>
$_SESSION['1'] = $_POST['textfield'];
>
echo("<html>\n<head>\n<title>Test</title>\n</head>\n<body>\n");
echo("<p>$_SESSION['1']</p>\n");
>
echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";
>
?>
>
<p>&nbsp;</p>
<p><a href="page2.php">page 2</a</p>
</body></html>
</snip>
>
Where's the <!DOCTYPE ... >, <html>, <headand <body>
tags? And do you have your cookies turned on in your browser?
>
--
Jim Carlock
Erwin Moller
Guest
 
Posts: n/a
#13: Nov 19 '06

re: Session Problems


Maximus wrote:
Quote:
Now here's something even more weird
>
<?
phpinfo();
?>
>
Hi

Try:
<?php
phpinfo();
?>


Maybe you didn't enable short open tags on your server.
(Check this by viewing the source from that page, it would read excactly:
<?
phpinfo();
?>
which displays nothing in a browser, since it looks just like an (unknown)
tag.

Regards,
Erwin Moller

Closed Thread