duanmu1736 2015-06-17 18:40
浏览 99
已采纳

如何根据正在使用的用户名创建文件夹的标头位置

I have a login form with a redirect to a menu page in the same directory that will link to other files in the same directory that are all shared by all the users in the database.

session_start();
$_SESSION['username'] = $username;
$_SESSION['password'] = $hash;
header("location:loginSuccess.php");

This works fine because loginSuccess.php is in the same directory as the login form.

But now I need the redirect to a particular sub-folder, depending on which user logged in. In other words, if user1 logs in, I want to redirect this user to /user1.loginSuccess.php, and if user2 logs in, I want to redirect this user to /user2/loginSuccess.php.

I tried the following:

header("location:/"<?php echo $username ?>"/loginSuccess.php");

I understand that this would translate to /user1/loginSuccess.php if user1 logged in, but got a message with an unexpected ? on line 43, which is the line with the above code.

I am self-taught in procedural php but relatively unfamiliar with object orientated php.

Any help and advise will be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • duanfang5849 2015-06-17 18:52
    关注

    this is called string concatenation. Сhange your code

    header("location:/"<?php echo $username ?>"/loginSuccess.php");
    

    to

    header('Location: /'.$username.'/loginSuccess.php');
    

    and check the docs String concatenation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?