dryift6733 2011-10-07 02:26
浏览 148
已采纳

使用$ _GET传递会员ID

Im having a problem when trying to create a member login system where each user is directed to their own editable profile. I'm at the login stage right now, and trying to pass the user's id securely from the login page to their profile page so that I can display their profile information.

Right now, I am being redirected to 'mydomain.com/index.php?test=Resource%20id%20#8', (I want, for example 'mydomain.com/index.php?test=1111') after this chunk of code:

$user_id = mysql_query("SELECT `id` FROM `users` WHERE `username` = '$user' AND `active`='1'");  
header("location: profile.php?test='$user_id'");
exit();

where $user has been sanitized using trim, htmlspecialchars, and mysql_real_escape_string. After the user arrives at 'profile.php,' I am planning on implementing something like this after I can figure out how to properly pass the user id:

$user_id=(int)$_GET['$user_id'];
mysql_real_escape_string($user_id);
if (isset($user_id)) {
   $user_id = preg_replace('#[^0-9]#i', '', $user_id); // filter everything but numbers

There is more to the code, but I believe I have included all relevant information. Any advice, wisdom, thoughts, and comments are always very much appreciated. Thank you very much for your support.

  • 写回答

2条回答 默认 最新

  • douyou2234 2011-10-07 02:32
    关注

    You cannot query and get the result right away.

    Try to fix above part as like this.

    $user_id = mysql_query("SELECT `id` FROM `users` WHERE `username` = '$user' AND `active`='1'");
    $user_id = mysql_result($user_id, 0, 'id');  
    header("location: profile.php?test='$user_id'");
    exit();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图