Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    need help with this script

    Hi,
    this is a part of a script I'm using to send url to an sms gateway.

    Code:
    $param["username"] = "test@yahoo.com";
    $param["password"] = "12345";
    $param["msg"] = "This is sample message.";
    $param["to"] = "2348023555555";
    $param["from"] = "MyCompany";
    
    foreach($param as $key=>$val){
    	//this is to urlencode the values
    	$request.= $key."=".urlencode($val);
    	//append the ampersand (&) sign after each paramter/value pair
    	$request.= "&";
    }
    //remove the final ampersand sign from the request
    $request = substr($request, 0, strlen($request)-1);
    my problem is with the username which is an email address, after the encoding the username appears as "%40" in the url that is sent. Is there a way I can prevent this so that it retains the "@" symbol in the resulting $request

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Replace
    PHP Code:
    $request.= $key."=".urlencode($val); 
    With
    PHP Code:
    if($key != 'username'){
      
    $request.= $key."=".urlencode($val);


  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply, but that will take out the username from the result... I'm not trying to take out the username but rather make it display the "@" symbol and not the encoded "%40"
    the result should be this:
    username=test@yahoo.com&password=12345&msg=This+is+sample+message.&to=234802888888&from=MyCompany

    and not this:
    username=test%40yahoo.com&password=12345&msg=This+is+sample+message.&to=2348028888&from=MyCompany

    hope it's clearer

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    oops, I meant to say replace it with this
    PHP Code:
    if($key == 'username'){
      
    $request.= $key."=".$val;
    }
      
    $request.= $key."=".urlencode($val); 

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nightfire View Post
    oops, I meant to say replace it with this
    PHP Code:
    if($key == 'username'){
      
    $request.= $key."=".$val;
    }
      
    $request.= $key."=".urlencode($val); 

    Thanks a lot...didn't need to be encoded...how come I didn't see that?

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts
    but here's another challenge at the end. I av this function at the end of the curl, to output the response from the sms server:

    curl_exec($ch)

    The sms sever responds with a 4-digit code, depending on the response...but I wish to display something else...eg.

    if the response is 1900, I want to display "Message sent successfully".

    I've tried if...elseif, doesn't give what I want...another help please


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •