Page 1 of 1

php action that will call a url

Posted: Wed Apr 19, 2006 4:21 pm
by Meni
This is a first part of a very long issue that I have.
I am currently building a php page that will use a service provider to send an SMS.

The SMS is sent by simply going to a URL (for example http://www.serviceprovider.domain.com/sms.sms) and then specifying several variables, so that the end result is a URL that will look like this:
http://www.serviceprovider.domain.com/s ... &user=user....
After calling that URL, the service provider answers by displaying an XML page with a result (i.e. - did the SMS go through or not)

I want to have a page that will be able to run that URL, and read the XML response, without the user even knowing about it.
Now, i am not too worried about reading the XML at this point. All I need right now is to be able to tell the server to call out that URL without actually redirecting the user's browser TO that URL.

I am VERY new to php and don't even know if this is possible...

Any help would be appreciated.

Thanks.

Posted: Wed Apr 19, 2006 9:25 pm
by RobertGonzalez
Don't know if it will work, but you can try http://www.php.net/curl]cURL.

Posted: Wed Apr 19, 2006 11:55 pm
by josh
file_get_contents()

Posted: Thu Apr 20, 2006 1:59 am
by Meni
file_get _contents does not help, because there is no such file on the sevrer... I am activating an action on the remote server by accessing the URL... not reading it's contents.


And I don't understand the usage for : [urlhttp://www.php.net/curl]cURL[/url].

Any other suggestions?

Posted: Thu Apr 20, 2006 10:46 am
by feyd
file_get_contents() can request (thus reading) the contents of a remote page.

Posted: Thu Apr 20, 2006 10:56 am
by Meni
Pardon my ignorance... But how do I use it?

I have an Array...

Code: Select all

<?php
$sql = "SELECT * FROM tbl1;
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>";
echo "<input type=\"checkbox\" name=\"cb\" value=\"".$row['mobilePhone']."\">";
echo "</td>";
echo "<td>".$row['firstName']."</td>";
echo "<td>".$row['lastName']."</td>";
echo "<td>".$row['sex']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['homePhone']."</td>";
echo "<td>".$row['mobilePhone']."</td>";
echo "<td>".$row['product']."</td>";
echo "<td>".$row['dateOfBirth']."</td>";
echo "<td>".$row['colorType']."</td>";
echo "<td>".$row['color1']."</td>";
echo "<td>".$row['color2']."</td>";
echo "<td>".$row['color3']."</td>";
echo "<td>".$row['oxygen']."</td>";
echo "<td>".$row['notes']."</td>";
echo "</tr>";
}
?>
I want to have a Loop that, for each checkbox (name=cb) will generate a URL, go to it, but without the user actually seeing it...

Posted: Thu Apr 20, 2006 11:47 am
by feyd
figure out how to generate that URL and you'll know how to get it's contents.

Posted: Thu Apr 20, 2006 4:18 pm
by Meni
Generally, when i post in a forum - I can't figure something out...
Help is what i seek...

Posted: Thu Apr 20, 2006 4:30 pm
by feyd
I have no idea what URL you want to generate so I can't help a whole lot unless you tell us more.

http_build_query() may be of interest. If you're using PHP 4, there's a PEAR Compatibility version of it available (linked to in that page's user comments)

Posted: Thu Apr 20, 2006 5:09 pm
by Meni
in my first post i specified info about the URL...
I guess you didn't see it... hence the confusion.

The URL is:

http://www.serviceprovider.domain.com/s ... 0123456789 etc etc etc
Where the part that changes every time in the array is the "TO" right in the end there.
For each row in the array there's a different TO...

Hope that clears out things...

Posted: Thu Apr 20, 2006 5:18 pm
by feyd
I saw it before and had to ignore it because it wasn't really specific. Now that you've clarified it a bit, what part of generating the URL are you having trouble with? If it's generating the number, I don't know how much help we can be there without knowing the encoding scheme the provider uses.

Posted: Fri Apr 21, 2006 1:01 am
by Meni
I have no problem generating the string once with the data from the DB.
All I need is the code to put inside the one i pasted here a few posts back, so th0at I will be able to include the URL in every loop, and how exectly do I call a certain URL (that I already have) without ACTUALLY redirecting the client browser to that URL...

Posted: Fri Apr 21, 2006 4:57 pm
by John Cartwright
jshpro2 wrote:file_get_contents()
feyd wrote:file_get_contents() can request (thus reading) the contents of a remote page.

how to request a page (and its variables) without redirecin'

Posted: Sun May 28, 2006 5:40 pm
by jjrumi
Hi there!

You should try:

Code: Select all

$url="http://bla.bla.com/bla.bla?bla=bla&...
$n=100; //How much do you wanna read...
$fd=fopen($url,"r");
$contenido=fread($fd,$n);
fclose($url);
I had the same problem you have, with a very similar aplication :)

Another way to do it is knowing if they (where you are requesting) have a port abilitated for this proposal (it use to be).
If so:

Code: Select all

$portNumber=443;
$fd=fsockopen("tls://www.enviosmasivos.net",$portNumber,$errno,$errstr);
if(!$fd){
    die("$errstr($errno)");
}

$output="GET /blablabla.php?blabla=$bla&blabla2=$bla... HTTP/1.1\r\n".
"Host: www.hotsname.com\r\n".
"Connection: Close\r\n\r\n";
//Ok, now that's a HTTP request... if you don't know what it is... take a book and learn it!
$result="";

fwrite($fd,$output);
while(!feof($fd)){
	$resultado .= fgets($enviar_sms,128); //Here you get the response.
}
fclose($fd);
Hope you find it useful!!!!

JuanLu.