[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Referer information lost on re-direct

Posted on 2004-08-22
7
Medium Priority
?
353 Views
Last Modified: 2008-03-03
I am doing this
header('location:'.$newurl);

to make a php page do a re-direct to a new url, but when the new page is displayed it dosnt have any referer.

Any ideas on how to make sure referer is always set? Is there a header function to set the referer?

0
Comment
Question by:wildzero
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 27

Expert Comment

by:Diablo84
ID: 11865912
the referer is unreliable anyway so as a general rule avoid using it, in these situations i usually advise using the sessions work around.

first page:

session_start();
$_SESSION['ref'] = $_SERVER['PHP_SELF'];


checking page:

session_start();
if (!isset($_SESSION['ref'])) {
 //referer is not set
}

you can alternatively check the value stored in the session too if you are checking multiple pages, eg.

session_start();
if (isset($_SESSION['ref']) && $_SESSION['ref'] == "/yourreferingpage.php") {
 //referer is set and is valid
}

make sure session_start(); is always at the top of your page
0
 
LVL 10

Author Comment

by:wildzero
ID: 11866113
The page that it is getting sent to is on another server so i can't do sessions. Referers is the best way and it works perfect, but when you re-direct with header('location......... it loses the data

0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 375 total points
ID: 11866404
As far as im aware the information should be retained none the less, even so i still would not advise trusting the referer as it is set client side and can be blocked from being sent so there will be cases where it will not be set, quote from the manual:

"The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted."

That said you could use a modification of the above code using cookies instead of sessions, example:

first page:

$ref = $_SERVER['PHP_SELF'];
setcookie("ref", $ref, time()+3600, "/", ".domain.com");

checking page:

if (isset($_COOKIE['ref']) && $_COOKIE['ref'] == "http://www.yourdomain.com/yourreferingpage.php") {
 //referer is set and is valid
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Author Comment

by:wildzero
ID: 11866433
Still dosn't quite solve it, as some of the pages it redirects to I can't alter the page. Simple testing shows that header:location removed the referer.....

I thought there could have been a header:referer that could be set..... or somthing.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11866444
I just done a test here

a.php

<?php
header("location: b.php");
?>

b.php

<?php
echo $_SERVER['HTTP_REFERER'];
?>

and b.php produces http://localhost/ - the referer so the header does not remove it
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11866469
heres my last idea for this one, and is probably even less practical then the previous suggestions

include the file on the second server in a file on the first server with restrictions, example:

server a file (called inc.php for example):

include('http://serverB.com/page.php');

top of page.php on server b

if ($_SERVER['HTTP_HOST'] != "http://serverA.com" || $_SERVER['PHP_SELF'] != "/inc.php") {
 die ("you cannot access this file directly");
}
0
 
LVL 2

Expert Comment

by:nsstone
ID: 11899449
Can you pass the referrer along in another variable (like a hidden input variable) and use it even if it isn't any longer strictly $_REFERRER?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question