3

I have been writing a module for our billing system at work, and it works beautifully. Unfortunately the API lacks a function that I need to terminate services immediately leaving me with the only option of calling the URL directly at...

http://www.website.com/billing/admin/clientsservices.php?userid=69264&id=68405&modop=terminate

As the module needs to continue to run without redirecting to that URL, how can I execute that from my PHP script?

2 Answers2

8

You could simply use file_get_contents();

<?php
file_get_contents('http://www.website.com/billing/admin/clientsservices.php?userid=69264&id=68405&modop=terminate');
?>

And it will be called.

Jonas m
  • 2,646
  • 3
  • 22
  • 43
  • WHMCS is behing a login, so you'd need to log in first, then run this function. – Prisoner Dec 19 '12 at 15:15
  • 1
    and i deserve a minus based on that when it is not clearly specified in the question? seems fair :) – Jonas m Dec 19 '12 at 15:17
  • would you put an "admin" folder in public hands? sometimes it's ok to use a bit of guess work :) – Prisoner Dec 19 '12 at 15:18
  • Thank you. I had seen that function posted elsewhere but was not clear on if that would work for my needs. I did just confirm what was stated by prisoner, as I noticed it failed to work but not at any fault of the answer. Would it be possible to automate the log in using CURL or something of that nature? PHP is not something I use often. –  Dec 19 '12 at 15:19
  • could use a ssl/apache password which alot of api does, which is possible to set with a url call, or simply a GET parametre. How should i know when its not specified. – Jonas m Dec 19 '12 at 15:21
  • @Brett Powell indeed curl could do the trick. Do you know what kind og authorisation the api requires? – Jonas m Dec 19 '12 at 15:22
  • I am not sure. I found AutoAuth on the WHMCS site at http://docs.whmcs.com/AutoAuth#Sample_Script but it is intended for Customer login integration. Trying to find something similar for the Admin side but not much luck as of yet. –  Dec 19 '12 at 15:23
  • You said you already had an API but it just lacked the ability to terminate, have you looked into how the API connects to the admin page? when im back at my pc i will post an edit with a valid curl script – Jonas m Dec 19 '12 at 15:29
  • I actually just thought about that as you mentioned it since I have used the External API in the past. The information on it is at http://docs.whmcs.com/API#External_API and it XML/JSON/NVP(not sure what that is) examples. Instead of passing it an "action" field, could I simply pass the username/pass to establish a session and then call the URL with file_get_contents()? –  Dec 19 '12 at 15:33
  • You would have to call the page with cUrl :-) Where would you usually log into your admin area? If you dont find this nice, public space fitting you can mail a URL to jonas AT mersholm.dk without the spaces and with AT replaced by @. – Jonas m Dec 19 '12 at 15:39
  • Thanks Jonas, I will shoot you an e-mail in just a couple of minutes. I appreciate all of the help with this :) –  Dec 19 '12 at 15:45
0

Why not just use curl to POST the data to the URL instead of using GET?

http://php.net/manual/en/book.curl.php

  • Based on his question, hes calling a different system which means he probably cant change between the _POST and _GET. Just my guess. – Jonas m Dec 19 '12 at 14:58