Jump to content

Strange behaviour of a Hook!


Belelros

Recommended Posts

Hi there,

 

I have this hook:

 

<?php

function setupweb($vars) {

$password= $vars["params"][password];

$email= $vars["params"][email];
$domain= $vars["params"][domain];

$subdomain=str_replace(".$main_domain", "", $vars["params"][domain]);
  exec("mysql -uroot -p$root_pass $subdomain < /home/master/master.sql");

$date = date("Y-m-d H:i:s");

$connection = mysql_connect("localhost","root","S4ha5do0w");

mysql_select_db("dbmydnsconfig", $connection);

$sql="INSERT INTO `dns_rr` VALUES('', 1, 0, 'riud', 'riud', '', 1, 5, '$subdomain', 'A', '$server_ip', 0, 86400, 'Y', '2010-04-30 17:21:16', 2010043002)";

$sqlb="INSERT INTO `hosting` VALUES('', '$subdomain', '$password','$date' ,'0','$_SERVER[HTTP_REFERER]','$_SERVER[REMOTE_ADDR]','$data')";

mysql_query($sql,$connection);
mysql_query($sqlb,$connection);


mysql_close($connection);
}

add_hook("AfterModuleCreate",1,"setupweb");

?>

 

And it makes it right. It creates a Database and also a folder and insert some data in a DB table. But then, I needed to insert more code which is:

 

mysql_select_db($subdomain, $connection);
$mailsql="UPDATE 'config'  set config_value='$email' where config_name like 'admin_email'";
mysql_query($mailsql,$connection);

 

The DB "selected" is the one created in this step:

 

exec("mysql -uroot -p$root_pass $subdomain < /home/master/master.sql");

 

I've tried to put in another function and execute it using

 

add_hook("AfterModuleCreate",2,"setupanotherfunction");

 

And also inside the function at the top but it doesn't do anything... anyone have any clues?

Link to comment
Share on other sites

You haven't included all the code there so I'm making assumptions here, but my best guess is that you aren't creating the variable in the second function. The $subdomain variable only exists inside that first function, it won't exist in another unless you declare it, or make it global.

Link to comment
Share on other sites

You haven't included all the code there so I'm making assumptions here, but my best guess is that you aren't creating the variable in the second function. The $subdomain variable only exists inside that first function, it won't exist in another unless you declare it, or make it global.

 

As I said, I tried to put that code in the first function (so it could use the subdomain variable) and when it is in a second function I copy all the variables again in that function.

 

The majority of the code is there

 

BTW, thanks for your help ^^

Link to comment
Share on other sites

What he is saying is, the variables will not carry over from function1 to function2 without defining them as globals. You'd have to redefine them in the second function

 

I don't know if you didn't understand but I certainly redefine them if they are in another function so that's not the problem. I just avoid copying that because it was the same text as above.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated