douvcpx6526 2012-01-19 07:05
浏览 40

查看个人资料页面 - 根据用户ID的不同,所看到的内容会有所不同。 会话问题

I have a site that I'm working on building. I have a login/registration system in place and a member profile system in place.

When a user logs in, they are automatically directed to their profile page. They have the option to click an edit profile link and edit their data. They can also click another link to go back to viewing their profile.

Currently this works great.

The issue I am having is that I have a link in the navigation bar called 'User List'. This link should fetch a list of all the current users in the database, which it does with uid=(appropriate user id #) at the end of the url, however, when you click on any of these links, the profile it returns is for that of the logged in user, and not that for the name that they clicked.

I am aware that the issue is caused by my function in the profile.php page which states:

<?php 

include('core/init.inc.php'); 

$user_info = fetch_user_info($_SESSION['uid']);

?>

Since the profile page is being told to use the session uid, I understand that any redirect to the profile.php page will show the logged in users info.

So, if I change this function to $_GET['uid']' then my problems flip. I am able to correctly view the profiles for the users in the user list but then my logged in user can no longer view their profile or edit it since there is no call to the session uid.

So, I guess I'm wondering how I fix this. How do you separate profiles that are not for the logged in person vs their own individual profile? Please let me know what code you need to see and I'd be happy to post it.

  • 写回答

1条回答 默认 最新

  • dongyan5815 2012-01-19 07:16
    关注

    You can make a check, If the $_GET['uid'] is set then fetch user info using this variable otherwise use the session variable to fetch the user info.

    <?php 
    
    include('core/init.inc.php');    
    if (isset($_GET['uid']) && $_GET['uid'] !='')
    {
       $user_info = fetch_user_info($_GET['uid']);
    }
    else
    {
       $user_info = fetch_user_info($_SESSION['uid']);
    }    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值