Results 1 to 12 of 12
  1. #1

    grabbing part of a domain from a wildcard

    Ok I have a wildcard setup on my domain. Now I'm going to assign users subdomains (in actuallity there not) but I want to know how to grab the username out of the domain. Like so

    username.domain.com

    How would I grab that with PHP?
    North Carolina Remote Hands | Dacentec | Hickory | Asheville | Charlotte | North Carolina
    DKraklan.me

  2. #2
    PHP Code:
    $_SERVER['HTTP_HOST']; 
    normally, no ?

  3. #3
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    PHP Code:
    echo current(explode('.','username.domain.com')); 
    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  4. #4
    I'm talking about grabbing the

    USERNAME part of username.domain.com
    North Carolina Remote Hands | Dacentec | Hickory | Asheville | Charlotte | North Carolina
    DKraklan.me

  5. #5
    Join Date
    Mar 2003
    Posts
    389
    How about something like:

    PHP Code:
    <?php
      $domain 
    "username.domain.com";
      (
    $user$dom$ext) = split('.'$domain);
       echo 
    "Username: $user";
    ?>
    Thats off the top of me head - should work.

    Ry

  6. #6
    This is the current URL not just some domain i'm supplied with. I need it to grab the domain itself.
    North Carolina Remote Hands | Dacentec | Hickory | Asheville | Charlotte | North Carolina
    DKraklan.me

  7. #7
    Quote Originally Posted by splatcatballa99 View Post
    This is the current URL not just some domain i'm supplied with. I need it to grab the domain itself.
    You've been given a solution to grab the full domain/hostname already, right?
    Code:
    $_SERVER['HTTP_HOST'];
    And you've been given a solution to split that string so that it gets just the bit that you want, right?
    Code:
    $domain = "username.domain.com";
    ($user, $dom, $ext) = split('.', $domain);
    echo "Username: $user";
    So combine those two concepts/techniques together and you've got your solution.

  8. #8
    Quote Originally Posted by abluegrape View Post
    How about something like:

    PHP Code:
    <?php
      $domain 
    "username.domain.com";
      (
    $user$dom$ext) = split('.'$domain);
       echo 
    "Username: $user";
    ?>
    Thats off the top of me head - should work.

    Ry
    That way errors out but If I do this

    PHP Code:
    $domain $_SERVER['HTTP_HOST'];
    list(
    $user$domain$tld) = split('.'$domain);
    echo 
    "Username: $user"
    it works. But the only problem is I don't think you can use . i nthe split function because it's supposed to use regexp. I don't know how to match it to a period.
    North Carolina Remote Hands | Dacentec | Hickory | Asheville | Charlotte | North Carolina
    DKraklan.me

  9. #9
    Backslash should escape special characters like '.' in regular expressions. If it's working, though, then I would think that it understands the way it is written just fine. If you're unsure, the best way to find out is to go have a look at the php documentation on split() and see what it says.

  10. #10
    Quote Originally Posted by jmichalicek View Post
    Backslash should escape special characters like '.' in regular expressions. If it's working, though, then I would think that it understands the way it is written just fine. If you're unsure, the best way to find out is to go have a look at the php documentation on split() and see what it says.

    It's not working, and i've been looking at the documentation thats how I know it needs regexp.
    North Carolina Remote Hands | Dacentec | Hickory | Asheville | Charlotte | North Carolina
    DKraklan.me

  11. #11
    Quote Originally Posted by splatcatballa99 View Post
    It's not working, and i've been looking at the documentation thats how I know it needs regexp.
    I'm not a php developer, so I'm basing this guess on examples I've seen.

    Try changing split('\.',$_SERVER["HTTP_HOST") to split("\.",$_SERVER["HTTP_HOST").

    If that doesn't do the trick, try this:
    explode(".",$_SERVER["HTTP_HOST"]) and see if that helps.

  12. #12
    Quote Originally Posted by jmichalicek View Post
    I'm not a php developer, so I'm basing this guess on examples I've seen.

    Try changing split('\.',$_SERVER["HTTP_HOST") to split("\.",$_SERVER["HTTP_HOST").

    If that doesn't do the trick, try this:
    explode(".",$_SERVER["HTTP_HOST"]) and see if that helps.
    thank you the \. worked.
    North Carolina Remote Hands | Dacentec | Hickory | Asheville | Charlotte | North Carolina
    DKraklan.me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •