Know if value coming from an input is a link from XX site. PHP - CodeIgniter

-1

Hello, I'm developing a site that would have the facebook profile on it, but we're afraid some smart guy will put any link there, someone would have a tip or a way to check if the link is from facebook, this is possible or am I traveling? I'm getting the possible link like this:

$this->Usuario_model->perfil_facebook = $this->input->post('link');

Thanks to anyone who can respond.

    
asked by anonymous 20.09.2016 / 14:36

1 answer

1

You can check if the address passed is a valid Facebook URL. The first thing that comes to mind is: - All facebook profile URLs should start with " link " or https.

So you can use substrings or regular expressions to validate, for example:

$url_facebook = $this->input->post('link');

// Passa: http://facebook.com/user/teste123
// Passa: https://facebook.com/user/teste123
// Erro: http://teste.com/user/teste123

if (preg_match("~^https?://facebook.com/.*~", $url_facebook) == 0) {
    // URL inválida
    echo "URL invalida";
}

Just be careful and validate all possible addresses for profiles on facebook.

    
20.09.2016 / 14:48