PDA

View Full Version : Action hook Hi, PreDomainRegister



Xeron
02-27-10, 07:50 PM
Hi,

What I need to have is before a domain is registered so action hook PreDomainRegister that the domain name is send to another system.

So for example if the domain = test.com I need it to send test.com throw destination.com/index.php?domain=test.com

Hope somebody can help me how i need to do this, everything i tried did not work at all :S

thehost5968
02-28-10, 12:57 AM
You will need to give more details as the way you have above nothing will happen at destination.com/index.php?domain=test.com unless a call to the page happens and as the client is on your whmcs site page and will stay it can not be your client.

I think you need to store the info at destination.com/index.php?domain=test.com or what is happening there?

Xeron
02-28-10, 10:46 AM
You will need to give more details as the way you have above nothing will happen at destination.com/index.php?domain=test.com unless a call to the page happens and as the client is on your whmcs site page and will stay it can not be your client.

I think you need to store the info at destination.com/index.php?domain=test.com or what is happening there?

At the moment destination.com/index.php?domain=… receives a domain it will be added to his database.

The thing is, I only need to have the domain name test.com (or whatever whmcs tells on predomainregister) send to destination.com/index.php so he can add it to his database.

Xeron
02-28-10, 11:26 AM
For example my last try:


<?php
function create($vars) {

$domain = $vars["domain"];

echo "
<form id=\"send\" action=\"http://destination.com/add.php\" method=\"post\">
<input name=\"domain\" value=\"<?php echo $domain; ?>\" type=\"text\" />
</form>


<script type=\"text/javascript\">
function myfunc () {
var frm = document.getElementById(\"send\");
frm.submit();
}
window.onload = myfunc;
</script>";
}

add_hook("PreDomainRegister",0,"create");
?>

m00
02-28-10, 11:41 AM
For example my last try:


<?php
function create($vars) {

$domain = $vars["domain"];

echo "
<form id=\"send\" action=\"http://destination.com/add.php\" method=\"post\">
<input name=\"domain\" value=\"<?php echo $domain; ?>\" type=\"text\" />
</form>


<script type=\"text/javascript\">
function myfunc () {
var frm = document.getElementById(\"send\");
frm.submit();
}
window.onload = myfunc;
</script>";
}

add_hook("PreDomainRegister",0,"create");
?>

That's not possible. Is this only something what should be posted on the background, or does the client als needs to get a output from that post?

Xeron
02-28-10, 12:02 PM
No, it only needs to send the domain given by WHMCS to the other system so he can add it to his database.

m00
02-28-10, 12:13 PM
You can try something like this:

<?php
function create($vars)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://destination.com/add.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("domain" => $vars['domain']));
$data = curl_exec($ch);
curl_close($ch);
}

add_hook("PreDomainRegister", 0, "create");
?>

It will be executed at the background. The client doesn't get any output from the hook process.

Xeron
02-28-10, 12:23 PM
I tried but get:


Warning: Cannot modify header information - headers already sent by (output started at /home/whmcs/includes/hooks/domain_hook.php:15) in /home/whmcs/admin/ordersadd.php on line 0

Line 15 = ?>

m00
02-28-10, 12:25 PM
Remove all spaces after the ?>.

Xeron
02-28-10, 12:31 PM
Ok that did the trick :) only the domain is not added on the other system

Current code there to get the domain variable


if (isset($_POST['domain'])) {
$domain = trim($_POST['domain']);
} elseif (isset($_REQUEST['domain'])) {
$domain = trim($_REQUEST['domain']);
} else {
$domain = "";
}

m00
02-28-10, 01:06 PM
Ok that did the trick :) only the domain is not added on the other system

Current code there to get the domain variable


if (isset($_POST['domain'])) {
$domain = trim($_POST['domain']);
} elseif (isset($_REQUEST['domain'])) {
$domain = trim($_REQUEST['domain']);
} else {
$domain = "";
}

That script shouldn't give any problems. To start with, you can add this to your "add.php" page:


mail("[email protected]","Domain Add","The domain add page was called.\n\nVariables:\n".print_r(get_defined_vars(), true));
It will send you an e-mail when the page is called (to verify that the action hook does it's job). In that e-mail are also the declared variables. Based on that, you can try to customize the add script.

Xeron
02-28-10, 01:16 PM
I don't get an e-mail, I also don't see anything in the access log that add.php has been called.

Xeron
02-28-10, 01:18 PM
********* - - [28/Feb/2010:14:33:06 +0100] "GET /add.php HTTP/1.1" 200 557 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
was the last log

m00
02-28-10, 01:24 PM
Add the following line under $data = curl_exec($ch); in your action hook:

if(curl_exec($ch) === false) die(curl_error($ch));
If there's a problem with the connection, it will display the error.

Xeron
02-28-10, 01:31 PM
also dont get a error, is this action hook working when i add an domain order throw the admin?

m00
02-28-10, 01:44 PM
When I send a domain name to the registrar, it just activates the action hook on my test environment.


<?php
function testje($vars)
{
die("stop!");
}

add_hook("PreDomainRegister", 1, "testje");
?>

Xeron
02-28-10, 01:52 PM
Well if I have made the order in the admin then set the registrar to none and made sure send to registrar is selected, I click on accept order. But the hook doesn’t do anything.

I now have edited the hook to your test hook, but it doesn’t do anything it just goes on as normally :S

m00
02-28-10, 02:01 PM
You have a PM with my contact details. I am willing to take a look.