473,623 Members | 2,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$HTTP_REFERER crashes my system like clockwork

I like to develop on my desktop, then when I get stuff working, I copy
to my web-site.

I set up a new version Xampp on my windows-2k desktop. And downloaded
the stuff from the website to edit. On the website, everything worked,
on my desktop, nothing works.

I am guessing this has to do with PHP versions. I know PHP breaks
everything whenever they come out with a new version.

On the website, I am using PHP 4.4.2. On my desktop, I'm using 5.1.4.

This is the routine that crashes everything.

#if either form field is empty return to the log-in page
if ( (!$username) or (!$password) )
{
header("Locatio n:$HTTP_REFERER ");
exit();
}

Again, it all works with PHP 4..4.2, crashes with PHP 5.1.4. Also if I
try to do anything else with $HTTP_REFERER, the system crashes.

By "crashes" I mean I either get a blank page, or an error message that
the headers are already loaded.

Jul 20 '06 #1
22 2432
walterbyrd wrote:
This is the routine that crashes everything.

#if either form field is empty return to the log-in page
if ( (!$username) or (!$password) )
{
header("Locatio n:$HTTP_REFERER ");
exit();
}

Again, it all works with PHP 4..4.2, crashes with PHP 5.1.4. Also if I try
to do anything else with $HTTP_REFERER, the system crashes.

By "crashes" I mean I either get a blank page, or an error message that
the headers are already loaded.
This may or may not help, but is there really no space between "Location:"
and "$HTTP_REFERER" ? Because there should be.

Also, you might try using $_SERVER['HTTP_REFERER'] instead, assuming you're
running PHP >= 4.1.0.

HTH,
--
Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
"I think I'd most like to spend a day with Harry. I'd take him
out for a meal and apologise for everything I've put him through."
— J. K. Rowling

Jul 20 '06 #2
Benjamin Esham wrote:
>
This may or may not help, but is there really no space between "Location:"
and "$HTTP_REFERER" ? Because there should be.
I found that I can set PHP to 4.4.2-pl1 with Xampp. That didn't help. I
tried putting in a space, that didn't help either.
Also, you might try using $_SERVER['HTTP_REFERER'] instead, assuming you're
running PHP >= 4.1.0.
I am not sure exactly how to do this. I had:

header("Locatio n: $HTTP_REFER");

Do I keep the quotes? Do I keep the "Location:" ? It doesn't seem to
work either way.

I tried it like this:

header($_SERVER['HTTP_REFERER']);

And got these errors:

Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:2) in
C:\xampp\htdocs \WMS\authentica te.php on line 5

I also don't understand why this works perfectly on my web-site. Also,
I don't understand why I'm not getting my $username and $password
strings.

This is from by index.html file:
<form action="authent icate.php" method="post">
Username:<br>
<input type="text" name="username" >
<br><br>
Password:<br>
<input type="password" name="password" >
<br><br>
<input type="submit" name="Log In">
</form>
This is the authenticate.ph p file:
<?php
#if either form field is empty return to the log-in page
if ( (!$username) or (!$password) )
{
header($_SERVER['HTTP_REFERER']);
exit();
}
The $username and $password strings seem to be empty. I tested them.
HTH,
--
Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
"I think I'd most like to spend a day with Harry. I'd take him
out for a meal and apologise for everything I've put him through."
- J. K. Rowling
Jul 20 '06 #3
[quoted sections rearranged slightly]

walterbyrd wrote:
Benjamin Esham wrote:
Also, you might try using $_SERVER['HTTP_REFERER'] instead, assuming
you're running PHP >= 4.1.0.

I am not sure exactly how to do this.
OK, try this function:

function authenticate()
{
if (!isset($_POST['username']) || !isset($_POST['password'])) {
header('Locatio n: ' . $_SERVER['HTTP_REFERER']);
exit();
}
}
The $username and $password strings seem to be empty. I tested them.
The $username and $password were empty because you have register_global s
off; this means that you can only access your form variables through $_POST.
*This is the way it should be!* Turning register_global s on is potentially
a great security risk. Newer versions of PHP ship with register_global s
turned off by default, which is probably why you're experiencing
inconsistencies between the behavior of the two versions.
Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:2) in
C:\xampp\htdocs \WMS\authentica te.php on line 5
This error is caused by sending output before headers. "Output" is usually
your outputted HTML code, but *any text at all*, including whitespace, that
comes before the opening <?php of your script will mess up your attempt to
send a header. Make sure that the <?php is the very first thing in your
file, and that you have no print or echo statements that are run before your
header() call.

By the way, I'm not sure whether using HTTP_REFERER is the best way to
return to the previous page. You're probably better off just doing a

header('Locatio n: login_form.php' );

as the HTTP_REFERER value is sometimes unreliable. Another alternative is
to display an error message instead of just sending the user back to the
input form. This is a bit more user-friendly; if a user clicks on "Submit"
and is sent back to the login page again, he or she might just try to submit
the form again and again until it works. With an error message, he or she
knows what the problem was.

Hope this helps! Feel free to post again if your script continues to give
you trouble.

--
Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
....and that's why I'm not wearing any pants.

Jul 20 '06 #4
*** walterbyrd escribió/wrote (20 Jul 2006 11:49:52 -0700):
#if either form field is empty return to the log-in page
if ( (!$username) or (!$password) )
{
header("Locatio n:$HTTP_REFERER ");
exit();
}
Do you check that $HTTP_REFERER actually has a value? Even if you have
register_global s set to on, you must be aware that browsers can send
HTTP_REFERER... or not.

If the variable is empty, it's not a good idea to send an empty location
header.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 20 '06 #5
Alvaro G. Vicario wrote:
*** walterbyrd escribió/wrote (20 Jul 2006 11:49:52 -0700):
#if either form field is empty return to the log-in page
if ( (!$username) or (!$password) )
{
header("Locatio n:$HTTP_REFERER ");
exit();
}

Do you check that $HTTP_REFERER actually has a value? Even if you have
register_global s set to on, you must be aware that browsers can send
HTTP_REFERER... or not.

If the variable is empty, it's not a good idea to send an empty location
header.
In that case I believe the browser would make a new request to the
current script, which of course, sends the redirect again. The
recursion would continue until the browser decides enough is enough and
kills the operation. That seems to match the symptoms described.

Jul 20 '06 #6
Benjamin Esham wrote:
Okay, I think I may be making some progress. My authenticate.ph p now
starts like this:

<?php
#if either form field is empty return to the log-in page
if (!isset($_POST['username']) || !isset($_POST['password']))
{
header("Locatio n: index.html");
exit();
}

And that seems to work.
The $username and $password were empty because you have register_global s
off; this means that you can only access your form variables through $_POST.
*This is the way it should be!* Turning register_global s on is potentially
a great security risk.
Okay, from now on I will have register_global s on. Er, how do I do
that?
This error is caused by sending output before headers. "Output" is usually
your outputted HTML code, but *any text at all*, including whitespace, that
comes before the opening <?php
I am certain that is not the case. I have absolutely nothing before the
<?php or after the ?>, not even white space.
By the way, I'm not sure whether using HTTP_REFERER is the best way to
return to the previous page. You're probably better off just doing a

header('Locatio n: login_form.php' );
Did that. It works. Thanks.
Hope this helps! Feel free to post again if your script continues to give
you trouble.
My script is still giving me trouble, only now in a different part.

This line:

setcookie("admi n", $username, time()+18000);

Is giving me this error:

Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:29) in
C:\xampp\htdocs \WMS\authentica te.php on line 30

I am certain that $username is set correctly. I checked.

And this line (directly after the setcookie line)

header("Locatio n: table_list1.php ");

is giving me this error:

Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:29) in
C:\xampp\htdocs \WMS\authentica te.php on line 32

I am certain that the file table_list1.php is correct, it's there. And
it works fine when run on my remote web-site.
--
Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
...and that's why I'm not wearing any pants.
Jul 21 '06 #7
walterbyrd wrote:
Okay, I think I may be making some progress. My authenticate.ph p now
starts like this [...] And that seems to work.
Good to hear.
Benjamin Esham wrote:
The $username and $password were empty because you have register_global s
off; this means that you can only access your form variables through
$_POST. *This is the way it should be!* Turning register_global s on is
potentially a great security risk.

Okay, from now on I will have register_global s on. Er, how do I do that?
Perhaps you misunderstood: most people consider register_global s a potential
security risk and advise to leave it off, as it seems to be already for you.
Either way, reading this page will do a better job of explaining.

http://us3.php.net/register_globals
This error is caused by sending output before headers. "Output" is
usually your outputted HTML code, but *any text at all*, including
whitespace, that comes before the opening <?php

I am certain that is not the case. I have absolutely nothing before the
<?php or after the ?>, not even white space.
OK, but does this file contain any right-to-left (e.g. Hebrew or Arabic)
text? Another recent thread in this group involved some phantom bytes at
the beginning of a file due to the different text direction, and the same
problem occurred there. (The reason that I'm being really persistent about
the beginning of the file is because I can't really think of any other
possible cause to this problem.)
By the way, I'm not sure whether using HTTP_REFERER is the best way to
return to the previous page. You're probably better off just doing a

header('Locatio n: login_form.php' );

Did that. It works. Thanks.
OK, cool.
My script is still giving me trouble, only now in a different part.

Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:29) in
C:\xampp\htdocs \WMS\authentica te.php on line 30
This is the same problem you were having before: somehow, text is being
outputted before the headers or cookie information can be sent. Go back
through your code; take a look at *everything* that happens between the time
your script is called and your cookie commands. Make sure that nothing
generates any output (remember, error messages count as output). Hopefully
the error rests with something in there.

HTH,
--
Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
"Men never do evil so completely and cheerfully as when they
do it from religious conviction." — Blaise Pascal

Jul 21 '06 #8

Benjamin Esham wrote:
Make sure that nothing
generates any output (remember, error messages count as output). Hopefully
the error rests with something in there.
First, thank you again for all of your help.

I am very sure nothing is being output before, or after the <?php . .
?>. I am using 100% English, no right to left languages. The very first
and last lines of this file are below:

<?php
#if either form field is empty return to the log-in page
.. . . .
?>

Here is the section that is giving me all the trouble, complete with
error checking echo statements:

{
echo("1" . "\n\n");
setcookie("admi n", $username, time()+18000);
echo("2" . "\n\n");
header("Locatio n: table_list1.php ");
echo("3" . "\n\n");
exit;
}

Here is the complete output:

1
Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:22) in
C:\xampp\htdocs \WMS\authentica te.php on line 23
2
Warning: Cannot modify header information - headers already sent by
(output started at C:\xampp\htdocs \WMS\authentica te.php:22) in
C:\xampp\htdocs \WMS\authentica te.php on line 25
3

Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
"Men never do evil so completely and cheerfully as when they
do it from religious conviction." - Blaise Pascal
Jul 21 '06 #9
Another thing I forgot to mention. If I comment out the problem lines,
I do not get the error message about headers, i.e.:

{
echo("1" . "\n\n");
# setcookie("admi n", $username, time()+18000);
echo("2" . "\n\n");
# header("Locatio n: table_list1.php ");
echo("3" . "\n\n");
exit;

}
Gives me this output:

1 2 3

Also, oddly enough, when this line is executed, it works fine. No error
messages:

header("Locatio n: index.html");

And, again, this all works fine on my remote web-host, which runs about
the same version of php. My web-host runs Linux, and I am using
windows.

Jul 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9551
by: John A. Irwin | last post by:
I'm very new to PHP and am trying to figure out how to parse out a variable "HTTP_REFERER". My reason for this is my site was recently "FEATURED" (sic) on a website called FARK.COM. Because of this I received over 100,000 Hits in less then one hour and it caused my host's server farm to crash. While I understand that I could move to a more robust Web Host, I would rather trap any further links from FARK and redirect them to a rejection...
2
5633
by: ssk | last post by:
Hello! I made a web site using PHP Open sources for message board. Everything's fine except one computer can't open a message writing page. The code that gives an error is the following. if(!eregi($HTTP_HOST,$HTTP_REFERER)) Error("Write in the normal way");
2
1660
by: M Smith | last post by:
On our web site we allow our members access to features hosted by another web site. The way the other web site authenticates users is to check the value of the HTTP_REFERER. If it comes from our Login.asp page it lets them in. When our users login to go to the other site, they login on our site's Login.asp page. When they click submit, our LoginCheck.asp page validates them and does a response.redirect to the other site. In most cases...
9
2968
by: Nicolae Fieraru | last post by:
Hi All, I try to use Request.ServerVariables("HTTP_REFERER") in a script and I discovered it doesn't work as expected. I use XP with SP2 and I created a link on a web site which points to an asp page which should show the referer. I placed a link on www.eleader.com.au/linkref.html and there is a link pointing to www.monitortest.net/referer.asp When I use my computer with XP SP2, and I click on the first link, I get no referer. But when...
4
5280
by: Ringo Langly | last post by:
Hi everyone, We're using an outside vendor to provide some content for our website, and they use the http_referer variable to verify their content is only viewed from subscribing customers. Anyway, we're using the mm_menu javascript menu for our web menus, and under only Internet Explorer it's not passing the http_referer -- which means any site of theirs we link to from the menu doesn't work. This works fine in Firefox, Mozilla, and...
28
4873
by: Prabhat | last post by:
Hello, I have the below requirement. When ever my website is opened by any link: say clicked from the google search result or a link from other website: Then I should able to know the referrer URL. How Do I get that? I know about Request.ServerVariables("HTTP_REFERER"). So I used this in
2
1986
by: John | last post by:
Hi I am trying to save the value of HTTP_REFERER so I can use it later on in the webform as below; Public Return_Address as string Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Return_Address = Request.ServerVariables("HTTP_REFERER")
5
2031
by: Paperback Writer | last post by:
Hi, I have the following code in my ASPX: private string pagina = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.ServerVariables.ToUpper()); The problem is it: When i call this page directly i get an error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
8
1852
by: tshad | last post by:
Why would HTTP_REFERER not be there in the Page_Load event? I am using it to determine whether a page was called from a particular page. I am doing: sTest = Request.ServerVariables("HTTP_REFERER") if (sTest = "") ORELSE (sTest.SubString(sTest.LastIndexOf("/")+1) <> "job_posting_new2.aspx") then newPosition = new Position
0
8227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4074
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2602
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1778
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.