How to fill in input field and submit form with Curl?

Asked

Viewed 706 times

0

How do I fill in the input and carry out Submit of form of that website https://appear.in/ using Curl?

I want to use the video chat system of this site in my project, it is very simple to create a new chat room, but in my project I need it to be done automatically by the system.

  • You know this is a GET method right? You just need to access the URL, for example, https://appear.in/Rodrigo-Fontes. When you "something" goes straight to "something".

1 answer

1


I recommend using their official Javascript API https://developer.appear.in, add this to your HTML (has to run on HTTP or HTTPS protocol, file may not support):

<script src="//developer.appear.in/scripts/appearin-sdk.0.0.4.min.js"></script>

And then call it:

var AppearIn = window.AppearIn || require('appearin-sdk');
var appearin = new AppearIn();

// verifica se o navegador usa WebRTC
var isWebRtcCompatible = appearin.isWebRtcCompatible();

if (isWebRtcCompatible) {
    //Cria uma sala
    appearin.getRandomRoomName().then(function (roomName) {
        //Após iniciar a sala
    });
}

If you have a specific room do so:

<iframe id="meu-iframe"></iframe>

And in Javascript this:

var minhaSala = "rodrigo-fontes";
appearin.addRoomToElementById("meu-iframe", minhaSala);

But if you still need PHP for some reason, like creating rooms dynamically, the use of Curl is relatively simple, apparently you have to use HTTPS, so do it like this:

$nomedasala = 'nome da sala';

$url = 'https://appear.in/' . urlencode($nomedasala);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//Define um User-agent
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0');

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

//Retorna a resposta
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Resposta
$data = curl_exec($ch);

If you get an error message about SSL or HTTPS then it is because your server is off, you need to enable SSL module, see how to do here /a/169474/3635

But if you can’t do it at all you can just turn off the check (which I don’t recommend):

//Desliga
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  • With the use of the API everything is OK. But when I went to test with Curl did not display anything on the screen, was simply blank, so I gave a var_dump($data) and ended up appearing a lot of characters and question marks. I just used your code in a PHP file with no HTML structure. Could you help me?!

  • @Rodrigofonts I just showed how to generate the room, display on the screen does not have much sense, after all will give several problems with CORS, the best in this case is to exchange for an iframe, for example <iframe src="https://appear.in/rodrigo-fontes"></iframe>

  • With the iframe worked (hehe), but with gz_decode gave HTTP ERROR 500. But it would have some way to redirect or open in a new tab the room on the site’s own appear.in, rather than clicking on an iframe?

  • With the var_dump(gzdecode($data)); almost worked. When you say that "Wouldn’t work due to locks" you refer to the image error asseguir: [Imgur]: http://i.imgur.com/O4kccij.png . Just keep trying to connect more nothing happens (this using the gzdecode).

  • @Rodrigofonts please pay attention, the scripts perform connection functions, they are released to run in the source domain, in case the scripts come from the domain appear.in, if you try to inject into another domain things like Ajax will not work due to security issues of the browser itself. Another thing that can occur are relative Urls not found, because if you use Curl the domain will be another and the tag pointing as <link> and <script> will not find the Resources. I hope that is clear ;)

  • Thanks Guilherme, helped me a lot! I managed to create the room with Curl and redirect with header('Location: '), will work for what I need.

Show 1 more comment

Browser other questions tagged

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