dongtanjian9310 2014-03-03 14:16
浏览 40
已采纳

在注册时创建目录

So i have a code to register and i want for each user that registers that he gets his own folder with same name as he registered and i dont know how to do that i heard there is mkdir but i m new to that so if anyone could help me out please where i should add that mkdir or something and whats the command!

here is my register.php:

<?php

require_once 'core/init.php';



if(input::exists()) {
    if(Token::check(Input::get('token'))) {
        $validate = new Validate();
        $validation = $validate->check($_POST, array(
            'username' => array(
                'required' => true,
                'min' => 2,
                'max' => 20,
                'unique' => 'users'
            ),
            'password' => array(
                'required' => true,
                'min' => 6
            ),
            'password_again' => array(
                'required' => true,
                'matches' => 'password'
            ),
            'name' => array(
                'required' => true,
                'min' => 2,
                'max' => 50
            )
        ));

        if($validation->passed()) {
            $user = new User();

            $salt = Hash::salt(32);


            try {
                $user->create(array(
                    'username' => Input::get('username'),
                    'password' => Hash::make(Input::get('password'), $salt),
                    'salt' => $salt,
                    'name' => Input::get('name'),
                    'joined' => date('Y-m-d H:i:s'),
                    'group' => 1
                ));
                Session::flash('home', '<h3>Registracija uspešna!</h3>');
                Redirect::to('mojprofil.php');

            } catch (Exception $e) {
                die($e->getMessage());
            }
        } else {
            foreach($validation->errors() as $error) {
                echo $error, '<br>';
            }
        }
    }
}

?>
  • 写回答

2条回答 默认 最新

  • dongshanni1611 2014-03-03 14:29
    关注

    You don't want the username as a directory name, with al the security flaws related to that. So I would suggest to create a unique directory name and store that also in your database in the user-row:

    (assuming the username is unique!! )

    .....
    try {
           //- Create a hashed directoryname based on the username
               $user_dir = md5(Input::get('username');
    
    
            $user->create(array(
                'username' => Input::get('username'),
                'password' => Hash::make(Input::get('password'), $salt),
                'salt' => $salt,
                'name' => Input::get('name'),
                'joined' => date('Y-m-d H:i:s'),
                'group' => 1,
                'directory' => $user_dir  //- Add this field also to your database
            ));
            Session::flash('home', '<h3>Registracija uspešna!</h3>');
    
           //- Create directory, use the right path: absolute/relative
               mkdir(__DIR_.'/path/to/'.$user_dir);
    
            Redirect::to('mojprofil.php');
    }
    .....
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line