Solved

PHP - Remove ?SOMETHING from a string

Posted on 2007-03-17
5
657 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 …
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.

815 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

11 Experts available now in Live!

Get 1:1 Help Now