Using sessions instead of $HTTP_REFERER

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Using sessions instead of $HTTP_REFERER

Post 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
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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() ?
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post 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??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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>';
?>
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post by soianyc »

Heres the results:

PHP Version: 5.0.4
Display Errors: Off
Error Level: Not E_ALL
Register Globals: On
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post 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
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
User avatar
soianyc
Forum Commoner
Posts: 61
Joined: Wed Mar 30, 2005 2:48 pm
Location: NY

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply