LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2005, 03:01 PM   #1
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Rep: Reputation: 18
PHP $_SERVER['HTTP_REFERER'] returns previous url?


Hello,

Is it normal for $_SERVER['HTTP_REFERERE'] to return the value of the previous url and not the one you'r on at the moment?

I have a page that contains links on the left column, each link targets the same page but adds another query to the url. => thus I redraw the same page but with another query.
Then some lines further in the script, it should go looking for this query in the string using $_SERVER['HTTP_REFERER'] to get the CURRENT url and then run a function that takes this query as a parameter to show a photo with the name of this query.
That is, it should do so but for some reason, the $_SERVER['HTTP_REFERER'] variable seems to hold the url of the previous page and thus doesn't show the photo I want but the one I clicked before.

part of my code: (it's part of a class category)

public function showMe() {
$url = $_SERVER['HTTP_REFERER']; echo "url: $url <br/>";
$urlvals = parse_url($url);
$url = $urlvals['scheme'] . '://' . $urlvals['host'] . ':' . $urlvals['port'];
$url .= $_SERVER['PHP_SELF']; echo "url: $url <br/>";
echo "<div id=\"leftcolumn\">";
$this->showPhotoLinkList($url);
echo "</div>";
echo "<div id=\"categories\">";
//$this->showPhoto("duiken1");
$url2 = $_SERVER['HTTP_REFERER'];
echo "url2: $url2 <br/>";
$vals = parse_url($url2);
if (isset($vals['query'])) {
$nm = $vals['query'];
echo "$nm <br/>";
//show the photo in the query
$pos = strpos($nm, '=');
$nm = substr($nm, ++$pos);
echo "$nm <br/>";
$this->showPhoto($nm);
}
echo "</div>";
}

The function gets called from an index page like:
$categ = new category($nm);
$categ->showMe();


Left I have links to photo1, photo2, photo3 (actually links to the same page but with a different query containing the name of the photo)
I open the page 1st time and have the url "http://lieven.isa-geek.net:8123/~lieven/categorytest.php"
I click on the link to the 1st photo (or the second or ...) and I get the url: "http://lieven.isa-geek.net:8123/~lieven/categorytest.php?photo=duik1" but HTTP_REFERER still shows the first one. I click again on a link and it shows the url with that query but then HTTP_REFERER contains the ".../photo=duik1" which is thus the previous one.

Is this normal?
 
Old 03-09-2005, 03:02 PM   #2
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 51
Yes.. the referer is where "you came from"

PS: If you read Slashdot you'll note that some servers check if your referer is slashdot.org so it stops you to load the page to avoid a flood on the server (any user with some knowledge will solve this in some secs anyway...

Last edited by gbonvehi; 03-09-2005 at 03:04 PM.
 
Old 03-09-2005, 03:12 PM   #3
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Quote:
Originally posted by gbonvehi
Yes.. the referer is where "you came from"

PS: If you read Slashdot you'll note that some servers check if your referer is slashdot.org so it stops you to load the page to avoid a flood on the server (any user with some knowledge will solve this in some secs anyway...
heh, I know /. I have seen those poor bastards being /.etted. and thus being knocked of the net by.. let's call it a DDOS attack. But not with bad intentions ofcourse. (Not like the bastard kids who do this things for fun)

But how can I refer to the current url? Maybe via headers_sent() or something alike? Problem with this headers is that they should be sent before any output is sent to the browser. (I think)

Any hints?
 
Old 03-09-2005, 03:19 PM   #4
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Maybe possible with $_SERVER['PHP_SELF'] ? I try with that but then I don't have the 'scheme', 'host' and 'port' ? not even the 'query'...

I'll have to combo these three:
PHP_SELF : /dir/foo.php
QUERY_STRING : fruit=apple&color=red
REQUEST_URI : /dir/foo.php?fruit=apple&color=red

regds

Last edited by ldp; 03-09-2005 at 03:23 PM.
 
Old 03-09-2005, 03:25 PM   #5
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 51
$_SERVER['PHP_SELF'] will tell you the current page. I don't know what you mean by don't having the scheme host and port, maybe this page can help you: http://ar2.php.net/reserved.variables

EDIT: Well seems you found the combo, good luck

Last edited by gbonvehi; 03-09-2005 at 03:27 PM.
 
Old 03-09-2005, 03:27 PM   #6
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
thanks for your patience, I did not look good enough...
 
Old 05-11-2018, 02:14 AM   #7
sagar03d
LQ Newbie
 
Registered: May 2018
Posts: 1

Rep: Reputation: Disabled
Smile You may want to store the previous page URL as an input type

You may want to store the previous page URL as an input type and send that to next page with form after that use that to return to previous page x 2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php $_SERVER value missing dinges Programming 6 12-23-2004 02:09 PM
Getting the url with PHP linux_pioneer Linux - General 2 06-20-2004 02:08 PM
# URL variable in PHP fatman Programming 1 06-04-2004 10:42 PM
PHP Url? HappyDude Programming 2 09-20-2003 04:20 PM
PHP question: HTTP_REFERER doesn't behave linuxfond Programming 6 09-08-2003 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration