Solved

PHP - Remove ?SOMETHING from a string

Posted on 2007-03-17
5
655 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
Comment Utility
$url = "http://www.mydomain.com/submit.php?SOMETHING";

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

0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
OR

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


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

Author Comment

by:Luv2Muff
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now