Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable construction

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

Would like to modify a .php script from phpformmailer, whereby the '.com' or whatever in the following code would become '.net', .org', depending on the current URL.
Code:
$valid_ref1="[URL unfurl="true"]http://mysite.com/contact.html";[/URL]
$valid_ref2="[URL unfurl="true"]http://www.mysite.com/contact.html";[/URL]
The values of the variables are error trapped as follows
Code:
$ref_page=$_SERVER["HTTP_REFERER"];
$valid_referrer=0;
if($ref_page==$valid_ref1) $valid_referrer=1;
elseif($ref_page==$valid_ref2) $valid_referrer=1;
if(!$valid_referrer)
{
 echo "<script language=\"JavaScript\"><!--\n alert(\"ERROR - not sent.\\n\\nCheck your 'valid_ref1' and 'valid_ref2' are correct within contact_process.php.\");\n";
 echo "top.location.href = \"contact.html\"; \n// --></script>";
 exit;
}
So if the user has accessed (there is only one actual site), as opposed to the script should still work.

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
a few things

* try holding the valid urls in an array, and using in_array() to test for validity
* never rely on the referrer. there is no requirement for a browser to submit it, and many people ensure that their browsers do not do so (for privacy).
* it's easiest just to put the .net equivalents in the array by hand but if you need to have it dynamic then a regular expression would suit you.
 
jpadie

Thanks for your reply and comments.

Simply commenting out the variables and error trapping enables the script to work as required.

Would appreciate any thoughts as to the wisdom or otherwise of such a solution in view of your comment:-
Code:
* never rely on the referrer.  there is no requirement for a browser to submit it, and many people ensure that their browsers do not do so (for privacy).

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Assigns the last four characters of the 'host_name' server variable to variable 'domainExtension'.

Code:
$domainExtension = substr(
    (string)$_SERVER['HTTP_HOST'],
    strlen((string)$_SERVER['HTTP_HOST'])-4,
    4
);

Note: You might want to do some double-checking on the validity of the assigned value.

-a6m1n0

A*(256)^3+B*(256)^2+C*(256)^1+D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top