V
V
votod2015-10-11 13:06:49
PHP
votod, 2015-10-11 13:06:49

How to remove the ":" sign and what's after it?

How to remove the ":" sign and what's after it?
I can not. I commented out what I was trying to use.
<?php
//Get the IP
if(getenv('HTTP_X_FORWARDED_FOR'))
{$ip = getenv('HTTP_X_FORWARDED_FOR');}
elseif(getenv('HTTP_CF_CONNECTING_IP'))
{$ip = getenv('HTTP_CF_CONNECTING_IP');}
/ /Connect to the database
$host = "localhost";
$user = "user";
$pass = "pass";
$db = "db";
$connect = @mysql_connect("$host", "$user","$pass");
@mysql_select_db("$db", $connect);
//Compare with ips in the database
$query = "
//$query = substr($query, strrpos($query, ':'));
//$$ip2 = end(explode($query, ':'));
//echo array_pop(explode($ip, ':'));
$result = @mysql_query($query);
if(@mysql_num_rows($result) > 0 ) {
exit ("You are banned!");
}else{
exit("You are not banned!");
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wol_fi, 2015-10-11
@wol_fi

$ip2 = preg_replace('/:.*$/', '', $ip);

A
Alexey Skobkin, 2015-10-11
@skobkin

$var = substr($var, 0, strpos($var, ':'));
Naturally, this option works well if the colon is always there. If it is not there, you need to either do checks or use the same explode().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question