/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] http referer output missing after &

Hello I am using http referrer to pass data.

$prev = $_SERVER[‘HTTP_REFERER’];

The browser should output:

[url]http://localhost/~jason/r_overview.php?LANG=EN&RID=7[/url]

But instead it outputs:

[url]http://localhost/~jason/r_overview.php?LANG=EN[/url]

Any ideas why the browser is not printing the full URL, ie. dat after the ‘&’?

I have google’d this problem and read some forums about a potential bug in Apache server, but other comments differ, with no resolution or anything really useful.

Appreciate any help.

Oh in case it helps, I am using Firefox 3.06 on MAC OSX to view and server is Apache 5.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 25.2009 — "&" is a special character in HTML. Use htmlspecialchars() or htmlentities() to escape the output.
Copy linkTweet thisAlerts:
@Hokie1200authorFeb 25.2009 — Tried that.

$prev = htmlentities($_REQUEST["prev"]);

$prev = htmlspecialchars($_
REQUEST["prev"], ENT_QUOTES);

Same output:

It is shown correctly in the URL, just not when printed to the screen.
Copy linkTweet thisAlerts:
@NogDogFeb 25.2009 — We may need some more context. How are you outputting it? What are you looking at where it outputs incompletely? Did you do a view source in your resulting browser window to see if anything "interesting" shows up in that part of the output?
Copy linkTweet thisAlerts:
@Hokie1200authorFeb 26.2009 — Hi,

I am outputting using an echo command at the top page of my php file; for example:

$prev = htmlspecialchars($_REQUEST["prev"], ENT_QUOTES);

echo $prev;

When I "View Source" the following is shown at the top:

http://localhost/~jason/r_overview.php?LANG=EN<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Copy linkTweet thisAlerts:
@Hokie1200authorMar 02.2009 — Hi All,

Thought I would post the solution to my problem.

The following is coded in my redirect page after a user/member trys to access something that they have to first be logged into use:

$prev = $_SERVER['HTTP_REFERER'];

$prev = str_replace("&", "-", $prev);

The redirect page will redirect the member to login page after 10 seconds.

The login page now contains:

$prev = str_replace("-", "&", $_REQUEST["prev"]);

After the user logs in, the 'prev' variable is passed to another header redirect and the user is redirected to the page that they were trying to access originally.

I discovered htmlspecialchars doesn't work because it was coding the '&' into '&amp;' where the 'amp' was being treated as a separate variable in the URL. So basically when I tried to retrieve the data from 'prev' variable it would only retrieve data up to the '&' where I was not getting the complete previous page's URL that I required that was originally passed through the 'prev' variable.

Hope this helps anyone that may face a similar problem in the future.
Copy linkTweet thisAlerts:
@andre4s_yMar 02.2009 — The other solution is : tell php which separator is used to parse input URL into variables.

set arg_separator.input in php.ini.
×

Success!

Help @Hokie1200 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...