FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Session variables..
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Session variables.. [message #177903] Thu, 26 April 2012 09:34 Go to next message
xs2karan3190 is currently offline  xs2karan3190
Messages: 4
Registered: April 2012
Karma: 0
Junior Member
I know there is some problem regarding session variables but I am not able to get what it is.. Kindly help.
my code is in 2 files...


test0.php--->

<html>
<body>
<?php

session_start();
$_SESSION['id']="1";
$_SESSION['psid']="admin";

echo $_SESSION['id']." ".$_SESSION['psid'];

?>
<form method="get" action="test1.php">
<div id="id" name="name">Hello mr.</div>

<input type="submit" name="click" />
</form>
</body>
</html>



test1.php--->

<html>
<body>
<?php
session_start();
echo $_SESSION['id']." ".$_SESSION['psid'];
$a=$_GET['id'];
echo $a;
?>
<br/>
<a href=test0.php">Back</a>
</body>
</html>
--------------------------------------------------------------------------- -----

At start I open the test0.php on my localhost and click on submit button,test1.php loads perfectly.But when I click on back buton in test1.php the url is "localhost\test0.php%22"...
and error msg is access forbidden..
where does this extra %22 come.???

PLZ HELP..
Re: Session variables.. [message #177905 is a reply to message #177903] Thu, 26 April 2012 09:39 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 26.04.2012 11:34, schrieb xs2karan3190(at)gmail(dot)com:
> I know there is some problem regarding session variables but I am not able to get what it is.. Kindly help.
> my code is in 2 files...
>
>
> test0.php--->
>
> <html>
> <body>
> <?php
>
> session_start();
> $_SESSION['id']="1";
> $_SESSION['psid']="admin";
>
> echo $_SESSION['id']." ".$_SESSION['psid'];
>
> ?>
> <form method="get" action="test1.php">
> <div id="id" name="name">Hello mr.</div>
>
> <input type="submit" name="click" />
> </form>
> </body>
> </html>
>
>
>
> test1.php--->
>
> <html>
> <body>
> <?php
> session_start();
> echo $_SESSION['id']." ".$_SESSION['psid'];
> $a=$_GET['id'];
> echo $a;
> ?>
> <br/>
> <a href=test0.php">Back</a>

If you want us to find errors, you must show your code EXACTLY how it is.

You have an unbalanced quote here. It should give you an error message.

/Str.
Re: Session variables.. [message #177909 is a reply to message #177903] Thu, 26 April 2012 12:10 Go to previous messageGo to next message
Olaf S. is currently offline  Olaf S.
Messages: 10
Registered: December 2011
Karma: 0
Junior Member
Am 26.04.2012 11:34, schrieb xs2karan3190(at)gmail(dot)com:
> I know there is some problem regarding session variables but I am not able to get what it is.. Kindly help.
> my code is in 2 files...
>
>
> test0.php--->
>
> <html>
> <body>
^^^^^There is an OUTPUT.
So session_start does not work.


correct:
<?PHP
session_start( .....

?>
<html>
etc
Re: Session variables.. [message #177910 is a reply to message #177903] Thu, 26 April 2012 12:36 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 4/26/2012 2:34 AM, xs2karan3190(at)gmail(dot)com wrote:
> I know there is some problem regarding session variables but I am not able to get what it is.. Kindly help.
> my code is in 2 files...
>
>
> test0.php--->
>
> <html>
> <body>
> <?php
>
> session_start();
> $_SESSION['id']="1";
> $_SESSION['psid']="admin";
>
> echo $_SESSION['id']." ".$_SESSION['psid'];
>
> ?>
> <form method="get" action="test1.php">
> <div id="id" name="name">Hello mr.</div>
>
> <input type="submit" name="click" />
> </form>
> </body>
> </html>
>
>
>
> test1.php--->
>
> <html>
> <body>
> <?php
> session_start();
> echo $_SESSION['id']." ".$_SESSION['psid'];
> $a=$_GET['id'];
> echo $a;
> ?>
> <br/>
> <a href=test0.php">Back</a>
> </body>
> </html>
> --------------------------------------------------------------------------- -----
>
> At start I open the test0.php on my localhost and click on submit button,test1.php loads perfectly.But when I click on back buton in test1.php the url is "localhost\test0.php%22"...
> and error msg is access forbidden..
> where does this extra %22 come.???
>
> PLZ HELP..

Make sure that:
1. Your <?php tag is the first entry on the file(page), not even a blank
line or space, or a header will be created and sent to the server prior
to session_start is called and will barf.

2. Make sure that session_start in the <?php tags is called before any
out put such as echo, print, header etc....

3. Sometimes it is good when debugging $_SESSION to check the entire
contents to ensure that what you want is not getting overwritten by a
current script. Use var_export($_SESSION). or
$session = var_export($_SESSION, true);
and then read out $session elsewhere if needed such as a mail() call if
you are testing a script not meant for display.
Re: Session variables.. [message #177911 is a reply to message #177909] Thu, 26 April 2012 13:12 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 26.04.2012 14:10, schrieb Olaf S.:
> Am 26.04.2012 11:34, schrieb xs2karan3190(at)gmail(dot)com:
>> I know there is some problem regarding session variables but I am not able to get
>> what it is.. Kindly help.
>> my code is in 2 files...
>>
>>
>> test0.php--->
>>
>> <html>
>> <body>
> ^^^^^There is an OUTPUT.
> So session_start does not work.
>
>
> correct:
> <?PHP
> session_start( .....
>
> ?>
> <html>
> etc

The problem of output before session_start():

It is very handy to set "output_buffering = 4096" or so in your php.ini, and all
these problems are gone.

If you have to output binary data you can even clear the buffer from unwanted stuff
before sending data.

/Str.
Re: Session variables.. [message #177915 is a reply to message #177911] Fri, 27 April 2012 00:35 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2012 9:12 AM, M. Strobel wrote:
> Am 26.04.2012 14:10, schrieb Olaf S.:
>> Am 26.04.2012 11:34, schrieb xs2karan3190(at)gmail(dot)com:
>>> I know there is some problem regarding session variables but I am not able to get
>>> what it is.. Kindly help.
>>> my code is in 2 files...
>>>
>>>
>>> test0.php--->
>>>
>>> <html>
>>> <body>
>> ^^^^^There is an OUTPUT.
>> So session_start does not work.
>>
>>
>> correct:
>> <?PHP
>> session_start( .....
>>
>> ?>
>> <html>
>> etc
>
> The problem of output before session_start():
>
> It is very handy to set "output_buffering = 4096" or so in your php.ini, and all
> these problems are gone.
>
> If you have to output binary data you can even clear the buffer from unwanted stuff
> before sending data.
>
> /Str.

Bad idea. It may or may not work if your host changes their settings,
for instance. It also adds unnecessary overhead and may hide errors in
your code (error messages can be buffered, also).

Much better is to just structure your code properly - i.e. ensure
session_start() is called before any output.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Session variables.. [message #177916 is a reply to message #177903] Fri, 27 April 2012 00:37 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/26/2012 5:34 AM, xs2karan3190(at)gmail(dot)com wrote:
> I know there is some problem regarding session variables but I am not able to get what it is.. Kindly help.
> my code is in 2 files...
>
>
> test0.php--->
>
> <html>
> <body>
> <?php
>
> session_start();
> $_SESSION['id']="1";
> $_SESSION['psid']="admin";
>
> echo $_SESSION['id']." ".$_SESSION['psid'];
>
> ?>
> <form method="get" action="test1.php">
> <div id="id" name="name">Hello mr.</div>
>
> <input type="submit" name="click" />
> </form>
> </body>
> </html>
>
>
>
> test1.php--->
>
> <html>
> <body>
> <?php
> session_start();
> echo $_SESSION['id']." ".$_SESSION['psid'];
> $a=$_GET['id'];
> echo $a;
> ?>
> <br/>
> <a href=test0.php">Back</a>
> </body>
> </html>
> --------------------------------------------------------------------------- -----
>
> At start I open the test0.php on my localhost and click on submit button,test1.php loads perfectly.But when I click on back buton in test1.php the url is "localhost\test0.php%22"...
> and error msg is access forbidden..
> where does this extra %22 come.???
>
> PLZ HELP..

In addition to what the others have said, your php.ini file on your
development system should ALWAYS have:

display_errors = on
error_reporting = E_ALL

If you had these you would have received an error message telling you
(pretty much) exactly what the error was.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Session variables.. [message #177917 is a reply to message #177905] Fri, 27 April 2012 06:33 Go to previous messageGo to next message
xs2karan3190 is currently offline  xs2karan3190
Messages: 4
Registered: April 2012
Karma: 0
Junior Member
Thanks.. Silly me , The unbalanced quote was culprit..

But another error crept out while the former one was solved...

PLZ take a look and Provide for a solutionn


code is....-->


<?php
session_start();
$_SESSION['psid']=111;
echo $_SESSION['psid'];
$psid=999;
echo " ".$_SESSION['psid'];
?>

the output is-->1111 1111

but if you reload the page 2nd time then output changes to---> "1111 9999"

and if you write session_destroy() at the end then the output remains unchanged..
how come local variable psid is overwritten over $_SESSION['psid'].??

I have manually configured apache and using PHP as an apache module(not using any package like xampp,wamp etc)...
Re: Session variables.. [message #177918 is a reply to message #177905] Fri, 27 April 2012 06:36 Go to previous messageGo to next message
xs2karan3190 is currently offline  xs2karan3190
Messages: 4
Registered: April 2012
Karma: 0
Junior Member
Thanks.. Silly me , The unbalanced quote was culprit..

But another error crept out while the former one was solved...

PLZ take a look and Provide for a solutionn


code is....-->


<?php
session_start();
$_SESSION['psid']=1111;
echo $_SESSION['psid'];
$psid=9999;
echo " ".$_SESSION['psid'];
?>

the output is-->1111 1111

but if you reload the page 2nd time then output changes to---> "1111 9999"

and if you write session_destroy() at the end then the output remains unchanged..
how come local variable psid is overwritten over $_SESSION['psid'].??

I have manually configured apache and using PHP as an apache module(not using any package like xampp,wamp etc)...
Re: Session variables.. [message #177921 is a reply to message #177918] Fri, 27 April 2012 08:52 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 27.04.2012 08:36, schrieb karan kumar:
> PLZ take a look and Provide for a solutionn
>
>
> code is....-->
>
>
> <?php
> session_start();
> $_SESSION['psid']=1111;
> echo $_SESSION['psid'];
> $psid=9999;
> echo " ".$_SESSION['psid'];
> ?>
>
> the output is-->1111 1111
>
> but if you reload the page 2nd time then output changes to---> "1111 9999"
>
> and if you write session_destroy() at the end then the output remains unchanged..
> how come local variable psid is overwritten over $_SESSION['psid'].??

to session_destroy():

you will have your session variables until the end of script. On the next request
they will be gone. The session id remains the same, but the session data is gone.

I find it a bit strange, this function cleans up after you.

/Str.
Re: Session variables.. [message #177922 is a reply to message #177917] Fri, 27 April 2012 08:59 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 27.04.2012 08:33, schrieb karan kumar:
> <?php
> session_start();
> $_SESSION['psid']=111;
> echo $_SESSION['psid'];
> $psid=999;
> echo " ".$_SESSION['psid'];
> ?>
>
> the output is-->1111 1111
>
> but if you reload the page 2nd time then output changes to---> "1111 9999"
>
> and if you write session_destroy() at the end then the output remains unchanged..
> how come local variable psid is overwritten over $_SESSION['psid'].??

The output is unchanged because you always set $_SESSION['psid']. You must first test
if it is set.

The change to "1111 9999" does not happen with the shown code.

/Str.
Re: Session variables.. [message #177923 is a reply to message #177917] Fri, 27 April 2012 10:30 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/27/2012 2:33 AM, karan kumar wrote:
> Thanks.. Silly me , The unbalanced quote was culprit..
>
> But another error crept out while the former one was solved...
>
> PLZ take a look and Provide for a solutionn
>
>
> code is....-->
>
>
> <?php
> session_start();
> $_SESSION['psid']=111;
> echo $_SESSION['psid'];
> $psid=999;
> echo " ".$_SESSION['psid'];
> ?>
>
> the output is-->1111 1111
>
> but if you reload the page 2nd time then output changes to---> "1111 9999"
>
> and if you write session_destroy() at the end then the output remains unchanged..
> how come local variable psid is overwritten over $_SESSION['psid'].??
>

In this example, $psid is not being overwritten by $_SESSION['psid'].
That's why you get the 1111 twice.

According to your code, it should not happen the second time either. Is
there any chance you've got register_globals on in your php.ini file?
If so, you should turn it off immediately. It's a huge security problem
and a "feature" which will be removed in PHP 6.

But it still doesn't explain why you get two different outputs.

BTW, the output is incorrect (according to your code, it should be '111
111'). Please be careful when copying your code as minor errors can
cause large differences in the results.

> I have manually configured apache and using PHP as an apache module(not using any package like xampp,wamp etc)...


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Session variables.. [message #177967 is a reply to message #177923] Thu, 03 May 2012 04:19 Go to previous messageGo to next message
xs2karan3190 is currently offline  xs2karan3190
Messages: 4
Registered: April 2012
Karma: 0
Junior Member
I turned the register global=off and now the code works correctly..Thanks a ton.

But could you explain as to how it gave 2 different outputs the first time..??

I tried searching but couldn't find an answer.
Re: Session variables.. [message #177968 is a reply to message #177967] Thu, 03 May 2012 12:11 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/3/2012 12:19 AM, karan kumar wrote:
> I turned the register global=off and now the code works correctly..Thanks a ton.
>
> But could you explain as to how it gave 2 different outputs the first time..??
>
> I tried searching but couldn't find an answer.

No, it makes no sense, unless there was something left over in your
browser's cache.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: const var, self:: or static::
Next Topic: Removing specific array items
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 03:37:46 GMT 2024

Total time taken to generate the page: 0.01944 seconds