Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Load string from string.domain.com ?

Hey, i want to make like homo.com
where it loads the string entered in STRING.domain.com
How can i do that?
Should do it:

PHP Code

<?php 
function get_sub_from_url($url) {
    
$data = parse_url($url);
    
$sub = explode('.', $data['host']);
    return 
$sub;
} 
PHP Code

<?php 
$url 
= "string.domain.com";
$string = explode('.', $url);
$string = $string['0'];
echo 
$string; 
That should work too.
Use explode();
Like, as right above me.
As for getting multiple sub directories (ex: http://example.name.homo.com), here's the way I would approach it:

PHP Code

<?php
$host 
= $_SERVER['HTTP_HOST'];

$hostarr = explode ('.', $host);

for (
$i = 0; $i < (count($hostarr) - 2); $i++)
    echo 
$hostarr[$i] . " ";
?>

That should do it - the -2 should remove the "domain.com" at the end and just get the subdomain(s). :)
It can also be a url rewrite feature of Apache which comes from the mod_rewrite module. It's behavior can be edited using directives written inside .htaccess file.
Yearh thanks for the codes..
But i mean if you go to example.domain.com
How do i then make it redirect to for example domain.com?lol=example
Use get on the local domain, to redirect -> subdomain.

PHP Code

<?php
ob_start
();

if (isset(
$_GET['redirect']))
{
    
header('Location: http://'.htmlspecialchars($_GET['redirect']).'.yoursite.com/');
}

ob_flush();
?>

redirect.php?redirect=Nathan

Should link to: http://Nathan.yoursite.com/


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by Linux.Dec 26, 2012 11:31 AM 30 469 Dec 26, 2012 11:31 AM
Last Post: Linux.
[PHP] by Webman.ioSep 12, 2012 07:40 AM 6 136 Sep 12, 2012 07:40 AM
Last Post: Webman.io