Solved

PHP - Remove ?SOMETHING from a string

Posted on 2007-03-17
5
661 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 look for a specific file type in a local or remote server directory using PHP.

761 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