Jump to content
Sign in to follow this  
hancham

Just "read" a simple response from php

Recommended Posts

hancham

Hello, I currently have a autoit application working, at some point I need it to access a .php on my website that will check some values at Mysql. If the values are OK than I need the php to pass this OK to the autoit, so the process can continue.. if not ok, the process will stop. Can anybody please help me? I`m new to autoit, I`m being reading tons of topics but all them seems to doing much more than I need, like download or uploading files or filling forms.. All I need is the OK response from PHP into the AUTOIT application...

It would be really great if someone helpe me!! Thank you very much

Share this post


Link to post
Share on other sites
ZacUSNYR

You could start by telling us what the PHP file is "returning". This isn't hard at all, just reading the source of the PHP file would do what you're looking for.

Share this post


Link to post
Share on other sites
hannes08

Hi hancham,

a simple InetRead() will do the trick.

:mellow:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
jvanegmond

Your question is vague, so I give you a simple example.

Make a file called in the webserver called "autoit-api.php". Put code in it something like this:

$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
    die('Invalid query: ' . mysql_error());
} else {
    echo $result;
}

The idea is that you will use this file to retrieve the data from the database, and just print it. Don't add any HTML. Print just the value.

Also make an AutoIt script on your own computer and call it "retrieve php value.au3" or similar. Put in it a code like this:

#include <INet.au3>
$value = _INetGetSource ( "http://www.mywebsite.com/autoit-api.php" )
MsgBox(0, "The value is:", $value)

Then AutoIt will make a message box with the value that he got from the php script.

Also: http://stackoverflow.com/questions/7056368/read-variables-from-browser-php-or-xml

Share this post


Link to post
Share on other sites
hancham

Thank you this really work like a charm! I did some changes for my application and everything is working!

Also, how can I do the reverse? Send variables from autoit to PHP ? is that possible using the sabe _InetGetSource ? how could I send the a POST method together ?

Share this post


Link to post
Share on other sites
hannes08

If you use GET messages, you can use InetRead() or _INetGetSource() and add the variables to the URL:

"http:/mywebsie.com/autoit-api.php?var1=1&var2=22&var3=33&nothing=0"


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
hancham

THanks for quick response.. Though that was a little too much for me LOL .. I`m pretty new to autoit and php it`s been pretty much a challenge. Anyway. this is my autoit code right now:

<autoit>

#include <INet.au3>

$INPUT_USERNAME = "popo"

$INPUT_PASSWORD = "007"

_InetGetSource("http://mysite.com/PHPTEST/dbcheckTESTE.php?username=" & $INPUT_NAME & "&password=" & $INPUT_PASSWORD)

</autoit>

I have no idea if the way I`m using will work. and if this is the correct syntax for the InetGetSource ... so in the oder hand my php that should receive this variables is like this:

<?php

//Getting from app

$username = $_POST['username'];

$password = $_POST['password'];

$result = mysql_query("INSERT INTO testeuser (username, pw) VALUES('$username', '$password' )") or die('Query failed: ' . mysql_error());

So please help!

Share this post


Link to post
Share on other sites
hannes08

Well, if you're using the URL you'll need to use the $_GET[] array in PHP or it will not work.

Perhaps somebody else from the Forum has some ideas on how to send POST variables.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
hancham

Do I need to use the GET function ? I thought if I use the POST i can also use the post to read the variables .. I run a example using 2 php files that pass variables to each other using only post. So I guess it should be the same, but intead AUTOIT to php using post .

Am I missing something?

Thank you

Share this post


Link to post
Share on other sites
hancham

ok so any Ideas how to send POST variables using _InetGetSource ?

Share this post


Link to post
Share on other sites
jvanegmond

ok so any Ideas how to send POST variables using _InetGetSource ?

Not just as easy. $_GET has the advantage that you just paste the variables in the URL, but $_POST is hidden in the request and not in the URL at all.

For making a POST request you must use this library:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.