Solved

PHP - Remove ?SOMETHING from a string

Posted on 2007-03-17
5
659 Views
Last Modified: 2012-08-14
<?php
$Referer = getenv("HTTP_REFERER");
if ($Referer == "http://www.mydomain.com/submit.php") {
echo "<script>alert('Spam protection!');window.location='http://www.mydomain.com';</script>";
exit();
}
if ($Referer == "") {
echo "<script>alert('Spam protection!');window.location='http://www.mydomain.com';</script>";
exit();
}

Sometimes the referer is http://www.mydomain.com/submit.php?SOMETHING

How can I remove the ?SOMETHING from $Referer

Thanks,

Luv2.
0
Comment
Question by:Luv2Muff
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 18739954
$url = "http://www.mydomain.com/submit.php?SOMETHING";

$urlarray = explode("?",$url);
$urlnew = $urlarray[0];

0
 
LVL 27

Expert Comment

by:yodercm
ID: 18739958
OR

$url = "http://www.mydomain.com/submit.php?SOMETHING";


$urlnew = substr($url, 0, strpos($url,"?")-1);
0
 

Author Comment

by:Luv2Muff
ID: 18739964
Yoder, thanks for your help. Would this work:

<?php
$Referer = getenv("HTTP_REFERER");
$Referer = substr($url, 0, strpos($Referer"?")-1);
if ($Referer == "http://www.mydomain.com/submit.php") {
echo "<script>alert('Spam protection!');window.location='http://www.mydomain.com';</script>";
exit();
}
0
 

Author Comment

by:Luv2Muff
ID: 18740025
Yoda - Thank you!!

I used this and it seems to work a treat:

<?php
$Referer = getenv("HTTP_REFERER");
$urlarray = explode("?",$Referer);
$Referer = $urlarray[0];
if ($Referer == "http://www.mydomain.com.com/submit.php") {
echo "<script>alert('Spam protection!');window.location='http://www.mydomain.com';</script>";
exit();
}
if ($Referer == "") {
echo "<script>alert('Spam protection!');window.location='http://www.mydomain.com';</script>";
exit();
}
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 18740059
function startsWith($string, $find, $caseInSensitive = false) {
  return $caseInSensitive
             ? strtolower(substring($string, 0, strlen($find))) == strtolower($find)
             : substring($string, 0, strlen($find)) == $find
             ;
}

if(startsWith($Referer, 'http://www.mydomain.com.com/submit.php', true)) {
}

-r-
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

856 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