Page 1 of 1
Using sessions instead of $HTTP_REFERER
Posted: Thu Sep 01, 2005 2:20 pm
by soianyc
I want to create a back link from a catalog page. I have implemented the follwing code
Code: Select all
$_SESSION['lastpage'] = $_SESSION['thispage']; // 'lastpage' is now what 'thispage' used to be
$_SESSION['thispage'] = $_SERVER['PHP_SELF']; // update 'thispage'
What happens is, the link is not updating.
http://www.treschicfurs.com/catalog2/maintest.php
This is a link of the site. When i click on a garment, it goes back to the main site. If i go and click on the jackets menu, and click the Return to catalog button, it goes to the main page. How do i update this link??
Regards
-soianyc
Posted: Thu Sep 01, 2005 3:02 pm
by soianyc
Actually I believe the link is updating. The problem i believe is the variables are not passing. I was under the impression that the variables would also get passed. If that is not the case, how would i get a link with the variables passed?
Posted: Thu Sep 01, 2005 3:04 pm
by Burrito
not sure what you mean by variables not getting passed. have you tried echoing $_SESSION['lastpage'].
you also might try print_r'ing the whole $_SESSION array to see what's in there...
Posted: Thu Sep 01, 2005 4:36 pm
by feyd
Code: Select all
Date: Thu, 01 Sep 2005 21:35:21 GMT
Server: Apache/1.3.33 (Unix) mod_fastcgi/2.4.2 FrontPage/5.0.2.2635 mod_jk/1.2.6
X-Powered-By: PHP/4.3.11
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Keep-Alive: timeout=15, max=248
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
there's no session cookie being set, nor the url's being adjusted. Did we forget to call
session_start() ?
Posted: Fri Sep 02, 2005 8:03 am
by soianyc
session_start() has been called. Im a bit confused?? Are cookies necessary for the urls to be tracked. Also the code which you have just posted, what does that do??
Posted: Fri Sep 02, 2005 8:16 am
by feyd
it's the HTTP response headers I got when going to the URL. If sessions were working, a cookie would be sent and/or most URL's on the page would be altered by php to include the session id.
Is error_reporting set to E_ALL? Try running the following (in a seperate script) and posting back the output:
Code: Select all
<?php
echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
echo '</pre>';
?>
Posted: Fri Sep 02, 2005 8:26 am
by soianyc
Heres the results:
PHP Version: 5.0.4
Display Errors: Off
Error Level: Not E_ALL
Register Globals: On
Posted: Fri Sep 02, 2005 8:31 am
by feyd
okay, go into your php.ini, changing error_reporting to E_ALL, display_errors to On, and turning off register_globals.
After you restarting httpd and running your script, I'm going to guess you'll see something like "cannot modify headers: headers already sent." This problem can be solved by walking through
this thread.
Posted: Fri Sep 02, 2005 8:45 am
by soianyc
Here is the error i got
Notice: Undefined variable: prevs in /home/u2/treschic/html/catalog2/maintest.php on line 113
Notice: Undefined variable: nexts in /home/u2/treschic/html/catalog2/maintest.php on line 113
just some undefined variables. Im looking throught that thread you posted
Posted: Fri Sep 02, 2005 9:57 am
by neophyte
An undefined variable error usually indicates you are trying to use a variable that doesn't exist. So you'll want to test for those values using isset(). If the values are using incoming data you'll want to make sure the data is what you expect it be too.
hope that helps.
Posted: Fri Sep 02, 2005 10:22 am
by soianyc
yep. Will change that. On my test machine im getting these errors.
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\apache2triad\htdocs\treschic\catalog2\maintest.php:4) in C:\apache2triad\htdocs\treschic\catalog2\maintest.php on line 4 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\apache2triad\htdocs\treschic\catalog2\maintest.php:4) in C:\apache2triad\htdocs\treschic\catalog2\maintest.php on line 4 Warning: header() expects at least 1 parameter, 0 given in C:\apache2triad\htdocs\treschic\catalog2\maintest.php on line 16 Notice: Undefined index: thispage in C:\apache2triad\htdocs\treschic\catalog2\maintest.php on line 23 Notice: Undefined variable: paginate in C:\apache2triad\htdocs\treschic\catalog2\maintest.php on line 89
Besides the unidentified variables im getting these errors. Im doing some research on this at the moment. hopefully i can figure out where the problem lies. Feyd gave me a tutorial on this and im googling this as well.
Posted: Fri Sep 02, 2005 10:48 am
by feyd
basically, you it's saying you have an echo/html type output on line 4 of C:\apache2triad\htdocs\treschic\catalog2\maintest.php
a session cannot start if output has started. The tutorial I posted earlier will walk through the common solutions, basically, it involves holding off output of anything until after the session can start (at the least).
"Best practice" is leaving output to the very last thing the script does.