How to make www.mysite.com/ + personal extension name?

Discussion in 'Web Design and Development' started by youlichika, Aug 27, 2010.

  1. youlichika macrumors member

    Joined:
    Aug 27, 2010
    #1
    Hello everybody, I have a PHP personal space systems. It allows user registration, then get a personal space. But all it points the URL address to www.mysite.com. What php documents should I modify, make it like FACEBOOK: each user has his own URL address, convenient to share with his friends. (www.mysite.com/ + personal extension name) Thanks.
     
  2. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #2
    With php you would do something like a mysite.com?name=user1

    Then call this from the php as i have shown below. This can get far more elaborate and you can use htaccess to rewrite mysite.com?name=user1 to mysite.com/user1
    PHP:
    <?php
    switch ($_REQUEST["name") {
        case 
    "user1":
            echo 
    "This is user 1's home page.";
            break;
        case 
    "user2":
            echo 
    "This is user 2's home page.";
            break;
        case 
    "user3":
            echo 
    "This is user 3's home page.";
            break;
    }
     
  3. youlichika thread starter macrumors member

    Joined:
    Aug 27, 2010
    #3
    babyjenniferLB,T=thanks.
    I have checked my php system. it has already had a .htaccess.
    I open it, it wrote somthing in it.

    HTML:
    AddCharset utf-8 .php
    AddDefaultCharset utf-8
    
    AddType image/ico ico
    AddType image/x-icon ico
    
    DirectoryIndex index.php
    Options -Indexes
    
    <Files ~ "\.(ini)$">
    deny from all 
    </Files>
    
    Then I add your code below it, it did not work.
    I am a newer for .htaccess.
    So would you like to help me more?
    have a nice day.
     
  4. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #4
    My code is for php not for htaccess. The htaccess code would be a little less complex. Start firstly by getting it right using the ?= method.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    When the person logs in you should be keeping track of who they are (using cookies or sessions) and you just redirect them as necessary. How to do this effectively will depend on the login system you're using.
     
  6. youlichika thread starter macrumors member

    Joined:
    Aug 27, 2010
    #6
    Thanks a lot. I'll try to add the code in my index.php, but it not work.
    The code is:

    HTML:
    session_start();
    if(empty($_SESSION['user_id'])){    
    header("location: myspace.php");
    }
    else header("location: myspace.php?id=".$_SESSION['user_id']);
    
    And the login.php code like:
    HTML:
        function run() {
            $user_id = isset($_REQUEST['user_id']) ? getSafeStr($_REQUEST['user_id']) : null;
    ...// $email, $password like $user_id
    
            switch($this->act) {
                case "start_anonymus":
    ...//database query
                    $_SESSION['user_id'] = $res_id;
                    return array("status" => "start_result", 
                                 "user" => array("id" => $res_id, 
                                                 "email" => "", 
                                                 "password" => ""));
                    break;
    
     

Share This Page