PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Mon Jul 16, 2018 11:26 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Vonage Click2CallU
PostPosted: Wed Dec 28, 2011 8:23 pm 
Forum Newbie

Joined: Wed Dec 28, 2011 8:02 pm
Posts: 1
The Vonage Click2CallU has been driving me nuts for a long time. I've searched EVERYWHERE for answers...but nodda. If you've tried to use it, you've most likely run into the same problems I did...
1) the https url provided exposes your vonage user name and password to the world (very bad!)
2) the PHP script provided by Vonage doesn't work - nobody seems to know why
3) the "fixed" PHP script which can be found after some intensive googling doesn't work either
4) everyone on the planet seems to have given up on click2callu back in 2008

So after searching for way too long, I decided to learn a bit of PHP and write my own script. Now please keep in mind that I am NOT a programmer and I'm quite positive there will be mistakes and far more efficient ways of doing this. But this is the best I could do and it actually works. It's presented here for all of you who are trying to get it to work and ran into the same problems I did. Without further adieu...voila (btw: if you can make it more efficient/better/etc. please feel free to post comments and feedback that make sense to us non-programmer types...i.e. just tell us exactly what we need to do to make it work rather than a bunch of blah blah blah theory that makes no sense without a compsci degree).

Syntax: [ Download ] [ Hide ]
// The phone number provided by your site visitor
$tonumber = $_POST["tonumber"];

// Your Vonage user name in the form of first.last
// Replace the XXXX with your first.last name
$username = ("XXXX");

// Your vonage password
// Replace the XXXX with your Vonage password
$password = ("XXXX");

// Your Vonage phone number including country code and area code
// Replace the XXXX with your Vonage phone number including country and area code
$fromnumber = "XXXX";

// The variable that defines the first part of the Click2CallU address
$url = "";

// The variable that puts all the infomration together and is used below to complete the call
$newurl = $url . "$username&password=$password&fromnumber=$fromnumber&tonumber=$tonumber";

// If page is not submitted to itself echo the form
if (!isset($_POST['submit'])) {


<!-- basic form validation to ensure the phone number consists of only numbers -->
<script type="text/javascript">
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) {; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

<!-- a little CSS styling to make the page look prettier -->
<style type="text/css">
.welcometext {
        font-family: Verdana, Geneva, sans-serif;
        font-size: 10px;
        color: #333;
<table width="400" border="0" cellspacing="0" cellpadding="0">
    <td width="400" height="72" align="left" valign="top" class="welcometext">Welcome to my Click2CallU page. By entering your phone number in the box below, complete with exit (011 if you are wanting me to call a number outside of North America), country and area code, my phone will ring and display your number. If I am able to receive your call, my phone system will automatically call you at the number you have provided, at no charge to you.<br /></td>

<!-- The form. This form submits to this page (self) and is limited to 20 characters -->  
    <td height="21" align="center" valign="middle"><form action="<?php echo $PHP_SELF;?>" method="post" onSubmit="MM_validateForm('tonumber','','RisNum');return document.MM_returnValue">
<input name="tonumber" type="text" id="tonumber" size="20" maxlength="20">&nbsp;
<input name="submit" type="submit" class="welcometext" value="Call Me">
      <span class="welcometext">Please allow up to 20 seconds for my call to connect to you.<br>
      North American example: 13105551212</span></td>

// This is the line of code that submits all the information to Click2CallU
$handle = fopen("".$newurl, "r");

The script has some very BASIC validation (checks to see if the phone number is actually a number). I'm sure someone who is smart can figure out a way of having the script ignore 900 and such type bogus numbers, or even numbers that don't fall into Vonage's 60 "free" countries.

Also...I don't know squat about CSS so I used a table instead. One improvement I'd like to make is to have the form provide some sort of response that the call is being placed after the visitor clicks the Call Me button. Can't figure out how to do that. Don't even know what to look for online!

I did find a comprehensive list of countries, country codes, and all area codes for those countries. Was thinking I could improve this by adding drop downs that automatically fill in the beginning part of the phone number from user selection. Maybe that's going too far with it...but couldn't help but think it'd make it easier for folks who are on the road etc. to fill in the form.

Anyway...enjoy! Thanks for letting me post this here. I hope it helps someone else and saves them the headaches I went through.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 9 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group