A
A
Alexander Sharomet2014-04-14 21:42:50
PHP
Alexander Sharomet, 2014-04-14 21:42:50

PHP - why does url checking on hosting not work?

Hello!
I have a question.
I have a Security class that describes a method

public function checkUrl($url){
        for($i=0;$i<count($url);$i++){
            $a[$i]=mysql_real_escape_string(addslashes($url[$i]));
        }
        return $a;
    }

Since the url is an array, I loop through each element of it through mysql_real_escape_string, since some queries are directly related to the database - for example, getting data via id (I don't know if I'm doing the right thing or not).
Then in the router, I describe this method using this method.
$url=Security::checkUrl($url);
The whole problem is that it works on the local machine, but not on the hosting (
What could be the problem here? Thank you!

Answer the question

In order to leave comments, you need to log in

6 answer(s)
1
1001001 111, 2014-04-15
@sharomet

try not to use mysql_* functions
mb hosting php does not support these functions =)

F
Flaker, 2014-04-14
@Flaker

// Функция получает ссылку на массив url
// После выполнения функции массив $url содержит экранированые данные
function secureUrl($url)
{
    foreach ($url as &$elem)
        $elem = mysql_real_escape_string(addslashes($elem));
    unset($elem);
}

// Usage:
//
// $url = Массив;
// secureUrl($url);


// Функция получает массив url
// Возвращает новый массив, содержащий экранированные данные
function getSecureUrl($url)
{
    $a = array();
    foreach ($url as $elem)
        $a[] = mysql_real_escape_string(addslashes($elem));
    return $a;
}

// Usage:
//
// $url = Массив;
// $url = getSecureUrl($url);

PS The first option is preferable because it uses less memory.

O
Oleg Krasavin, 2014-04-15
@okwinza

Either make the checkUrl() method static:
Or use a dynamic call:

$obj = new Security();
$url = $obj->checkUrl($url);

Depending on the distribution, the interpreter reacts differently to calling non-static methods via::

A
Alexander Sharomet, 2014-04-14
@sharomet

No. There is no error. it just constantly gives me the main page even when I go through the menu items ..
and on the local server everything works
the whole problem is in this method

public function checkUrl($url){
        for($i=0;$i<count($url);$i++){
            $a[$i]=mysql_real_escape_string(addslashes($url[$i]));
        }
        return $a;
    }

if you just write
public function checkUrl($url){
        return $url;
  }

then everything works

A
Alexander Sharomet, 2014-04-15
@sharomet

function secureUrl($url){
    foreach ($url as &$elem)
        $elem = mysql_real_escape_string(addslashes($elem));
    unset($elem);
}

Doesn't even work on my local machine.
function getSecureUrl($url){
    $a = array();
    foreach ($url as $elem)
        $a[] = mysql_real_escape_string(addslashes($elem));
    return $a;
}

A good function, but it works the same way as my function - that is, it does not work(
Doesn't...
$obj = new Security();
$url = $obj->checkUrl($url);

Everything works the same
try not to use mysql_* functions
mb hosting php does not support these functions =)

Yes that's right. Thank you! mysql_real_escape_string is not supported

A
Alexander Sharomet, 2014-04-15
@sharomet

Doesn't work because I'm using PDO which doesn't work with mysql_real_escape_string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question