SMS Code Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moleuser
Forum Newbie
Posts: 2
Joined: Sat Feb 24, 2007 3:36 am

SMS Code Problem

Post by moleuser »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi Everybody,

I have this code and the sms code itself is ok its just the code before it. The code before it checks the user file to see if there are any credits in it, the file will have the number 10 in. Then the script is supposed to take that number and take away 1 and then save the file again and this would be when someone sends a message a credit gets taken off. The rest of the script works perfectly fine and it just this bit, please can someone help.

Thanks 

Joel Kennedy

Code: Select all

<?php
$to = $HTTP_POST_VARS['to'];
$fromout = $HTTP_POST_VARS['from'];
$messageout = $HTTP_POST_VARS['message'];
$username = $HTTP_POST_VARS['username'];
$usercredits = file('memberfiles/'.$username.'credits.sms');
$noone = "1";
$take = "-"
$fp = fopen("memberfiles/".$username."credits.sms", "w") or die("Couldn't create new file"); 
fwrite($fp, $usercredits.$take.$noone); 
fclose($fp);

//set up variables
$info = '1'; 
$address = 'www.txtlocal.com/sendsmspost.php';
$message = $messageout;
$message = urlencode($message); //encode special characters (e.g. £,& etc)
$from = $fromout;
$uname = '*********'; 
$pword = '******';
$selectednums = $to; 

//build url
$data = 'uname=' . $uname . '&pword=' . $pword . '&message=' . $message . '&from=' . $from . '&selectednums=' . $selectednums . '&info=' . $info;

//send messages
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,"https://$address");
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec ($ch); 
curl_close ($ch); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

This answer is brought to you by the functions file_get_contents(), file_put_contents() and the decrement operator.
moleuser
Forum Newbie
Posts: 2
Joined: Sat Feb 24, 2007 3:36 am

Post by moleuser »

Thanks for the reply, how should I fix it, I don't know how to, im still learning :cry:
Post Reply