Page 1 of 1

SMS Code Problem

Posted: Sat Feb 24, 2007 3:43 am
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]

Posted: Sat Feb 24, 2007 4:44 am
by Kieran Huggins
This answer is brought to you by the functions file_get_contents(), file_put_contents() and the decrement operator.

Posted: Sat Feb 24, 2007 5:31 am
by moleuser
Thanks for the reply, how should I fix it, I don't know how to, im still learning :cry: