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

Asked

Viewed 74 times

-1

Hello, I am developing a site that would have the facebook profile on it, but we are afraid that some smart guy put any link there, someone would have a tip or a way to do to check if the link is 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 those who can answer.

  • How is a facebook profile link? has a specific format?

  • would be the link of the person type https://www.facebook.com/meu_profile

1 answer

1


You can check if the address you passed is a valid Facebook URL. The first one that comes to mind is: - Every Facebook profile URL should start with "http://facebook.com/" 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 facebook profiles.

  • Attention, that www.fb.com is the same as www.facebook.com...

  • 1

    @Pedroluzio, I think the most important thing in this case is logic. The ideal is to allow a single format and warn the user that only http(s) addresses are accepted://facebook.com - fb.com itself is mere redirect.

  • I thought about going through the ip associated with the url

Browser other questions tagged

You are not signed in. Login or sign up in order to post.