Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #5739 > unrolled thread
| Started by | xs2karan3190@gmail.com |
|---|---|
| First post | 2012-04-26 02:34 -0700 |
| Last post | 2012-04-26 20:37 -0400 |
| Articles | 16 — 6 participants |
Back to article view | Back to comp.lang.php
Session variables.. xs2karan3190@gmail.com - 2012-04-26 02:34 -0700
Re: Session variables.. "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-26 11:39 +0200
Re: Session variables.. karan kumar <xs2karan3190@gmail.com> - 2012-04-26 23:33 -0700
Re: Session variables.. "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-27 10:59 +0200
Re: Session variables.. Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-27 06:30 -0400
Re: Session variables.. karan kumar <xs2karan3190@gmail.com> - 2012-05-02 21:19 -0700
Re: Session variables.. Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-03 08:11 -0400
Re: Session variables.. karan kumar <xs2karan3190@gmail.com> - 2012-05-03 23:19 -0700
Re: Session variables.. Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-04 07:36 -0400
Re: Session variables.. karan kumar <xs2karan3190@gmail.com> - 2012-04-26 23:36 -0700
Re: Session variables.. "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-27 10:52 +0200
Re: Session variables.. "Olaf S." <thesys@gmx.de> - 2012-04-26 14:10 +0200
Re: Session variables.. "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-26 15:12 +0200
Re: Session variables.. Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-26 20:35 -0400
Re: Session variables.. Scott Johnson <noonehome@chalupasworld.com> - 2012-04-26 05:36 -0700
Re: Session variables.. Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-26 20:37 -0400
| From | xs2karan3190@gmail.com |
|---|---|
| Date | 2012-04-26 02:34 -0700 |
| Subject | Session variables.. |
| Message-ID | <22074986.120.1335432844876.JavaMail.geo-discussion-forums@pbgg7> |
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..
[toc] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-26 11:39 +0200 |
| Message-ID | <9vsjfdFj9mU1@mid.uni-berlin.de> |
| In reply to | #5739 |
Am 26.04.2012 11:34, schrieb xs2karan3190@gmail.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.
[toc] | [prev] | [next] | [standalone]
| From | karan kumar <xs2karan3190@gmail.com> |
|---|---|
| Date | 2012-04-26 23:33 -0700 |
| Message-ID | <30831126.627.1335508430505.JavaMail.geo-discussion-forums@pbcoq1> |
| In reply to | #5741 |
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)...
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-27 10:59 +0200 |
| Message-ID | <9vv5g9F5slU1@mid.uni-berlin.de> |
| In reply to | #5754 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-04-27 06:30 -0400 |
| Message-ID | <jndsgn$5lv$1@dont-email.me> |
| In reply to | #5754 |
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@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | karan kumar <xs2karan3190@gmail.com> |
|---|---|
| Date | 2012-05-02 21:19 -0700 |
| Message-ID | <31561155.103.1336018792080.JavaMail.geo-discussion-forums@pbnh4> |
| In reply to | #5760 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-05-03 08:11 -0400 |
| Message-ID | <jntsmg$4pt$1@dont-email.me> |
| In reply to | #5806 |
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@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | karan kumar <xs2karan3190@gmail.com> |
|---|---|
| Date | 2012-05-03 23:19 -0700 |
| Message-ID | <7122537.316.1336112347218.JavaMail.geo-discussion-forums@pbnh2> |
| In reply to | #5807 |
I have cleared my browser's cache and temporary files but still the output remains ---> 111 999 when the browser is refreshed 2nd time and register golbals is turned on... I am still looking for a reason but unable to find..
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-05-04 07:36 -0400 |
| Message-ID | <jo0f0e$9be$1@dont-email.me> |
| In reply to | #5816 |
On 5/4/2012 2:19 AM, karan kumar wrote: > I have cleared my browser's cache and temporary files but still the output remains ---> 111 999 when the browser is refreshed 2nd time and register golbals is turned on... > > I am still looking for a reason but unable to find.. My guess is that there's more to your code than you're showing us. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | karan kumar <xs2karan3190@gmail.com> |
|---|---|
| Date | 2012-04-26 23:36 -0700 |
| Message-ID | <19098981.177.1335508561294.JavaMail.geo-discussion-forums@pblz5> |
| In reply to | #5741 |
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)...
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-27 10:52 +0200 |
| Message-ID | <9vv51oF2nnU1@mid.uni-berlin.de> |
| In reply to | #5755 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "Olaf S." <thesys@gmx.de> |
|---|---|
| Date | 2012-04-26 14:10 +0200 |
| Message-ID | <4f993b25$0$6547$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #5739 |
Am 26.04.2012 11:34, schrieb xs2karan3190@gmail.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
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-26 15:12 +0200 |
| Message-ID | <9vsvttFhq0U1@mid.uni-berlin.de> |
| In reply to | #5746 |
Am 26.04.2012 14:10, schrieb Olaf S.: > Am 26.04.2012 11:34, schrieb xs2karan3190@gmail.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.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-04-26 20:35 -0400 |
| Message-ID | <jncpkr$abg$2@dont-email.me> |
| In reply to | #5748 |
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@gmail.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@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2012-04-26 05:36 -0700 |
| Message-ID | <jnbfgl$e4i$1@dont-email.me> |
| In reply to | #5739 |
On 4/26/2012 2:34 AM, xs2karan3190@gmail.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.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-04-26 20:37 -0400 |
| Message-ID | <jncpnn$abg$3@dont-email.me> |
| In reply to | #5739 |
On 4/26/2012 5:34 AM, xs2karan3190@gmail.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@attglobal.net ==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web