Solved

PHP - Remove ?SOMETHING from a string

Posted on 2007-03-17
5
662 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:
Cornelia Yoder 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:Cornelia Yoder
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

751 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