Jump to content

Cpanel Subdomain Creation


Recommended Posts

Hello

Please i am doing a php script that creates a subdomain but it doesn't work

Here is the code


<?
$username = $_POST['subdomain'];
$path="http://seifhate:pass@seifhatem.co.cc:2082/frontend/x3/subdomain/doadddomain.html?rootdomain=seifhatem.co.cc&domain=$username";
$f = fopen($path, "r");
echo $path;
fclose($f);
?>
<html>
<form method="POST" action="">
Subdomain: <input type="text" name="subdomain"/>
<input type="submit" name="submit" value="Create"/>
</html>

please help

Thanks in advance

Link to comment
Share on other sites

Yeah, sorry about that careless mistake.

 

Just use above code (without the careless mistake), except without the echo statement. The code should look like this:

<?
$username = $_POST['subdomain'];
$path="http://seifhate:pass@seifhatem.co.cc:2082/frontend/x3/subdomain/doadddomain.html?rootdomain=seifhatem.co.cc&domain=$username";
$f = fopen($path, "r");
stream_get_contents($f);
fclose($f);
?>
<html>
<form method="POST" action="">
Subdomain: <input type="text" name="subdomain"/>
<input type="submit" name="submit" value="Create"/>
</html>

 

BTW, I would just run a cron script every 24 hours that updates cPanel with your database data.

Link to comment
Share on other sites

Try this:

 

<?
$username = $_POST['subdomain'];
$path="http://seifhate:pass@seifhatem.co.cc:2082/frontend/x3/subdomain/doadddomain.html?rootdomain=seifhatem.co.cc&domain=$username";
$f = fopen($path, "r");
file_put_contents(__DIR__.'/log.txt',stream_get_contents($f));
fclose($f);
?>
<html>
<form method="POST" action="">
Subdomain: <input type="text" name="subdomain"/>
<input type="submit" name="submit" value="Create"/>
</html>

.

 

Then, check the contents of log.txt to see the problem

 

BTW, I would just run a cron script every 24 hours that updates cPanel with your database data.

Sorry i can't understand this part

 

You can do this in your cPanel under "cron jobs." See this for instructions of how to create a PHP cron script.

  • Like 1
Link to comment
Share on other sites

You really should put that script inside an if statement. That way it will only try to execute when the form is submitted.

 

<?
if ($_POST['subdomain'])
{

$username = $_POST['subdomain'];
$path="http://seifhate:pass@seifhatem.co.cc:2082/frontend/x3/subdomain/doadddomain.html?rootdomain=seifhatem.co.cc&domain=$username";
$f = fopen($path, "r");
file_put_contents(__DIR__.'/log.txt',stream_get_contents($f));
fclose($f);

}
?> 
<html> 
<form method="POST" action=""> 
Subdomain: <input type="text" name="subdomain"/> 
<input type="submit" name="submit" value="Create"/> 
</html>

 

Link to comment
Share on other sites

This entire script he has is not very secure, as someone could possibly inject malicious content into the $username parameter, but it's his account.

  • Like 1
Link to comment
Share on other sites

Hello

Here is a part of mu final code enter to database,crete subdomain and ftp if anyone need it he can copy it or post it on other forums.

Thanks for xaav for helping me with it

<?php
include 'mysql-connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$strCheckUserSQL = "SELECT * FROM subs WHERE username='$username'"; 
$CheckUserQuery = mysql_query($strCheckUserSQL); 
$strCheckEmailSQL = "SELECT * FROM subs WHERE email='$email'"; 
$CheckEmailQuery = mysql_query($strCheckEmailSQL);
$path="http://seifhate:pass@seifhatem.co.cc:2082/frontend/x3/subdomain/doadddomain.html?rootdomain=seifhatem.co.cc&domain=$username";
$path2="http://seifhate:pass@seifhatem.co.cc:2082/frontend/x3/ftp/doaddftp.html?login=$username&password=$password&quota=13";
mysql_query("INSERT INTO subs (username, password, firstname, lastname, ip, email) 
VALUES ('$username', '$password', '$firstname', '$lastname', '$ip', '$email')");
$f = fopen($path, "r");
stream_get_contents($f);
$f2 = fopen($path2, "r");
stream_get_contents($f2);

but there is a problwm am facing that johnny is extremely slow and always returns an error and sometimes just do one or two of the three (subdomain,ftp and mysql) so can anyone help me with a sample cron script that retrieves data from mysql and create the subdomain abd ftp accounts because i am new to cron scripts.

Thanks in advance

Link to comment
Share on other sites

First, you need to modify your "subs" table to include "created" column. Make this column a type of boolean, and give it a default value of FALSE.

 

Then, break this up into two scripts.

 

First script:

<?php
include 'mysql-connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$strCheckUserSQL = "SELECT * FROM subs WHERE username='$username'";
$CheckUserQuery = mysql_query($strCheckUserSQL);
$strCheckEmailSQL = "SELECT * FROM subs WHERE email='$email'";
$CheckEmailQuery = mysql_query($strCheckEmailSQL);

// You really should escape these values, but I'm not going to do that here
mysql_query("INSERT INTO subs (username, password, firstname, lastname, ip, email)
VALUES ('$username', '$password', '$firstname', '$lastname', '$ip', '$email')");

 

Create this cron script in your [home] folder, NOT your public_html folder.

 

#!/usr/bin/php
<?php
$strCheckSubSQL = "SELECT * FROM subs WHERE created=false";

//Connect to the database

$result = mysql_query($strCheckSubSQL);
while($row = mysql_fetch_array($result)) {
//Create the user in cPanel
//Update the record with created=true
}

//Close the connection

 

You'll also need to chmod the cron script to 777.

  • Like 1
Link to comment
Share on other sites

So the first acript will be in the public_html folder normallyand the user will register to add the user to the db

And the cron script is in home that will be excuted manually to get the uncreated users and create them, am i right??

And what do you mean with escaping these values in script 1

Thank you very vey much :)

Link to comment
Share on other sites

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.

×
×
  • Create New...