Connecting Tech Pros Worldwide Help | Site Map

Help with simple email script please

  #1  
Old July 17th, 2005, 10:57 AM
Dynamo
Guest
 
Posts: n/a
Hi

I have used the following script within a simple form email to prevent the form
being used from an external url.
<?php
$referer = $_SERVER['HTTP_REFERER'];
// Get the URL of this page
$myurl= "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
// If the referring URL and the URL of this page don't match then
// display a message and don't send the email.
if ($referer != $myurl) {
echo "You do not have permission to use this script from another URL.</br>";
echo "Referer = $referer </br>";
echo "This url = $myurl</br>";
exit;
}
?>
I added the last 2 echo statements to see why there was always a mismatch and
the email was never sent and found that:
$referer = http://mydomain/myemailscript.php
while
$myurl = http://mydomain

I can easily get round the problem by amending as follows:

$myurl=$myurl . "/myemailscript.php" but is this correct? Is
$_SERVER['HTTP_REFERER'] returning correctly?

Regards
Dynamo

  #2  
Old July 17th, 2005, 10:58 AM
iMedia
Guest
 
Posts: n/a

re: Help with simple email script please


I have found that $_SERVER[HTTP_REFERRER] is not very reliable. I also
came across a document or two that also stated the referrer variable is
not reliable.

$myurl could be more reliable if you use:

if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] =
$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
}

$myurl =
"http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];

A great resource:
http://us2.php.net/reserved.variables

This is one I use:
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!eregi($page, $_SERVER['HTTP_REFERER'])){
echo "You are not authorized...";
}

function eregi() helps to find the important "needle" in the string
http://us2.php.net/manual/en/function.eregi.php

  #3  
Old July 17th, 2005, 10:58 AM
iMedia
Guest
 
Posts: n/a

re: Help with simple email script please


I have found that $_SERVER[HTTP_REFERRER] is not very reliable. I also
came across a document or two that also stated the referrer variable is
not reliable.

$myurl could be more reliable if you use:

if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] =
$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
}

$myurl =
"http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];

A great resource:
http://us2.php.net/reserved.variables

This is one I use:
$page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (!eregi($page, $_SERVER['HTTP_REFERER'])){
echo "You are not authorized...";
}

function eregi() helps to find the important "needle" in the string
http://us2.php.net/manual/en/function.eregi.php

  #4  
Old July 17th, 2005, 10:58 AM
Tim Van Wassenhove
Guest
 
Posts: n/a

re: Help with simple email script please


In article <1102785588.908212.108970@z14g2000cwz.googlegroups .com>, iMedia wrote:[color=blue]
> I have found that $_SERVER[HTTP_REFERRER] is not very reliable. I also
> came across a document or two that also stated the referrer variable is
> not reliable.
>
> $myurl could be more reliable if you use:
>
> if (!isset($_SERVER['REQUEST_URI'])) {
> $_SERVER['REQUEST_URI'] =
> $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
> }
>[/color]

following this group, i once saw this one:

function geturl()
{
$ports = array('https' => 443, 'http' => 80);
$prefix = empty($_SERVER['HTTPS']) ? 'http' : 'https';
$url = $prefix;
$url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : '';
$url .= '://';
$url .= $_SERVER['HTTP_HOST'];
$url .= $_SERVER['REQUEST_URI'];
return $url;
)


--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with simple form parse & email simononestop answers 5 December 13th, 2007 06:09 PM
Need help with $_POST lovinlazio9 answers 9 December 2nd, 2006 07:01 PM
Some help with a php script.. benson_james@yahoo.com answers 1 August 11th, 2006 02:35 PM
Help with form validation with gen_validatorv2.js (desperate) this one answers 2 April 20th, 2006 11:49 PM