Forum Moderators: coopster

Message Too Old, No Replies

generate sub domains from txt file

         

tyggemannen

11:49 pm on Jun 19, 2006 (gmt 0)

10+ Year Member



Hi.
I use this code in the browser to create subdomains:
[[domainhere]:2082...] here]&rootdomain=[maindomain.com]

Its easy to create subdomains this way, but how can I use this code in a php script to make many subdomains from a txt file with words, without having to write in the [subdomain here] manually?

Big thanks in advance.

alce

6:18 am on Jun 20, 2006 (gmt 0)

10+ Year Member



I suppose you could do semething like this:

Read the txt file and store the subdomain names in an array or just hard code the array
if you do not have too many words.

$subdomains = array('sub1', 'sub2', 'sub3');

then loop trough the array and echo links with the values you need:

echo "<ul>\n";
foreach ($subdomain as $sub) {
echo "<li><a href=\"javascript:window.open('http://[domainhere]:2082/frontend/rvlightolive/subdomain/
doadddomain.html?domain=$sub&rootdomain=[maindomain.com]' , '$sub')\" />Create new subdomain: $sub</a></li>\n";
}
echo '<ul>';

Then you just need to click each one of the links to open a new browser window with the URL you need.

Now pardon my ignorance but how this thing about creating subdomains work?
Does that mean anyone who knows how to build the URL with the porper values can create a subdomain?

Is one of the variables a password? I'm just curious since I've never heard of this before

tyggemannen

8:58 am on Jun 20, 2006 (gmt 0)

10+ Year Member



Thanks a lot alce. My subdomain list are sometimes 50 or maybe 250 words want to avoid to hardcode it.
The code I use, I use it after logging in to control panel, its the same code you get when you make sub domains the normal way, I just change the sub domain name in the address bar and click enter.

eelixduppy

12:09 pm on Jun 20, 2006 (gmt 0)



To get the information from a text file, you could do something like this:

domains.txt


subdomain1,maindomain1.com
subdomain2,maindomain2.com
subdomain3,maindomain3.com
...etc

links.php


$line = file [us3.php.net]("domains.txt");
$line = array_map [us3.php.net]("rtrim [us3.php.net]",$line);
$count = count [us3.php.net]($line);
for($i = 0; $i < $count; $i++)
{
$domains = explode [us3.php.net](",",$line[$i]);
echo '<a href="http://[domainhere]:2082/frontend/rvlightolive/subdomain/doadddomain.html?domain='.$domains[0].'&rootdomain='.$domains[1].'">Create sub: '.$domains[0].' main: '.$domains[1].'</a><br />';
}

Good luck ;)

tyggemannen

3:00 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Thanks a lot for your kind help.

I was able to do it in another way, more automatickly. Like this:

<?php
$words = file("subdomains.txt");
foreach ($words as $word) {
$response = file_get_contents(
"http://user:pass@IP:2082/frontend/rvlightolive/subdomain/doadddomain.html?domain=$word&rootdomain=maindomain.info");

//do error checking by seeing if $response contains the HTML output of that URL you expect
}
echo "Done! Added " . count($words) . " subdomains.";
?>

alce

5:08 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



sweet!

tyggemannen

6:14 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



But the script(or maybe the server) times out, so after making about 30 subdomains it makes no more.

alce

6:27 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Take a look at [php.net ]

tyggemannen

6:31 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



I already had a look there, but I dont understand it. I really dont know php : )

alce

7:08 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Well, I am no expert either but see if this does the trick:

<?php
$words = file("subdomains.txt");
set_time_limit(0);
foreach ($words as $word) {
$response = file_get_contents(
"http://user:pass@IP:2082/frontend/rvlightolive/subdomain/doadddomain.html?domain=$word&rootdomain=maindomain.info");

//do error checking by seeing if $response contains the HTML output of that URL you expect
}
echo "Done! Added " . count($words) . " subdomains.";
?>

If it doesn't, you might have to change the max_execution_time value in the php.ini.

tyggemannen

7:27 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Thanks, but it didnt work. Something about set_time_limit dont work in safe mode? sleep didnt work either.

alce

7:40 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Ok. We are going to try a couple of things to see if we can make it work.

Add these lines at the top of your script:

ini_set("safe_mode" , "0");
ini_set("max_execution_time" , "100");

eelixduppy

7:40 pm on Jun 20, 2006 (gmt 0)



Try:

//I think it's either 0 or -1 for unlimited time (or maybe I'm completely wrong...lol)
[url=http://us2.php.net/manual/en/function.ini-set.php]ini_set[/url]("[url=http://us2.php.net/manual/en/ref.info.php#ini.max-execution-time]max_execution_time[/url]","0");

Good luck!

[edit];)[/edit]

tyggemannen

8:01 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Your solutions didnt worked I am sorry to say. Thanks anyway.

alce

8:20 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Contact your hosting provider, they should be able to tell you how and if you can change these settings.

tyggemannen

10:29 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Ok, thanks for helping out.