PHP登录脚本 - 用户配置文件循环

时间:2011-08-10 20:12:37

标签: php session loops

我正在使用的系统没有查看其他用户个人资料的选项(仅限您自己的)(其他用户的个人资料我的意思是http://domain.com/profile.php?user=USERNAME)。但是,原来的,有它。 我想将它植入新系统,所以我为个人资料创建了一个新的php文件。

我下载了这个登录系统:
http://tympanus.net/codrops/2009/09/16/php-login-system-reloaded-v1-1/

这是该系统的自定义版本:
http://jpmaster77forum.conceptbb.com/t1-php-login-system-with-admin-features-download

以下是原始userinfo.php代码:

<?
include("include/session.php");
?>

<html>
<title>Jpmaster77's Login Script</title>
<body>

<?
/* Requested Username error checking */
$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||
   !eregi("^([0-9a-z])+$", $req_user) ||
   !$database->usernameTaken($req_user)){
   die("Username not registered");
}

/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
   echo "<h1>My Account</h1>";
}
/* Visitor not viewing own account */
else{
   echo "<h1>User Info</h1>";
}

/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);

/* Username */
echo "<b>Username: ".$req_user_info['username']."</b><br>";

/* Email */
echo "<b>Email:</b> ".$req_user_info['email']."<br>";

/**
 * Note: when you add your own fields to the users table
 * to hold more information, like homepage, location, etc.
 * they can be easily accessed by the user info array.
 *
 * $session->user_info['location']; (for logged in users)
 *
 * ..and for this page,
 *
 * $req_user_info['location']; (for any user)
 */

/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
   echo "<br><a href=\"useredit.php\">Edit Account Information</a><br>";
}

/* Link back to main */
echo "<br>Back To [<a href=\"main.php\">Main</a>]<br>";

?>

</body>
</html>

这是我的新profile.php

<?php
include('config/db_con.php');
include('config/config.php');
$page = 'profile';
include('header.php');
require_once("php/core.php");

$objCore = new Core();

$objCore->initSessionInfo();
$objCore->initFormController();

    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
$get_email = $objCore->getSessionInfo()->getUserInfo('email');
$get_flname = "SELECT * FROM `users` WHERE email = '$get_email'";
$res = mysql_query($get_flname) or die(mysql_error());
$rows = mysql_fetch_array($res);
$gemail_hash = md5( strtolower( trim( "$get_email" ) ) );
$req_user = trim(strtolower(str_replace(" ", "", $rows['flname'])));
?> 
<div class="content">
    <div class="left">
        <div class="top_box" style="margin-top:0px;">
            <p><h90>Profile: <?php echo $rows['flname']; ?></h90><?php echo $req_user; ?></p>
        </div>
        <div class="box_pad">
            <div class="box" style="border-bottom:1px solid #dbdbdd;">  
                <?php if($objCore->getSessionInfo()->isLoggedIn()){ ?>
                        <img class="gravatar" src="http://www.gravatar.com/avatar/<?php echo $gemail_hash; ?>?d=mm" />
                        <h1><?php echo $rows['flname']; ?></h1><br />
                        <a href="editaccount.php">[Edit Account]</a>
                        <? if($objCore->isAdmin()) ?>
                            <a href="admin.php">[admin]</a>
                        <a href="php/corecontroller.php?logoutaction=1">[Logout]</a>
                        <? }else{ ?> 
                        blabla test
                        <? } ?>

       <?php unset($objCore); ?>
            </div>
        </div>
    </div>
    <div class="right">
        <? include('ad.php'); ?> 
    </div> 
</div>
<?include('footer.php');?>
</body>

它不起作用'因为当试图访问其他用户的个人资料时,我再次看到我的。 如何定义file.php?user=USERNAME url模式?

非常感谢你! 我真的需要这个,我在Google上找不到任何东西,因为我真的不知道要搜索什么。 对不起,如果缺少信息,我尽量做到描述性。

1 个答案:

答案 0 :(得分:1)

很长一段时间,这是一些不好的编程。

  1. 短标签是邪恶的,像所有大社区建议不要使用它们。使用由使用短标签的人编写的脚本更糟糕。
  2. trim(strtolower(str_replace( .....如果用户名在数据库中,带有空格/大写字母,为什么要将其删除?)而不是在它获取INTO数据之前。< / LI>

    我可以继续,但不会解决你的问题......

    无论如何:

    $get_email = $objCore->getSessionInfo()->getUserInfo('email');
    $get_flname = "SELECT * FROM `users` WHERE email = '$get_email'";
    
    代码中的

    表示您正在根据用户会话获取数据。因此不是网址部分中的那个。

    原文:

    $req_user = trim($_GET['user']);
    if(!$req_user || strlen($req_user) == 0 ||
       !eregi("^([0-9a-z])+$", $req_user) ||
       !$database->usernameTaken($req_user)){
       die("Username not registered");
    }
    

    将从URL获取用户信息。

    但是,有一个问题,为什么你的生活变得复杂?为什么要使用profile.php来实现它的目的呢?如果你正在尝试做我在想的事情,你应该重命名 profile.php =&gt; myaccount.php userinfo.php =&gt; profile.php

    肯定会使你的生活变得复杂。还记得重命名引用。