douzongluo7542 2018-08-30 12:47
浏览 51
已采纳

PHP - 如何使用cookie中的值重定向到个人资料页面

I'm making a website that has a simple profile system.

All my profiles have a separate .php file with their id in a name like 1.php, 2.php and so on.

On index navigation bar, I have the option to go to persons own profile (my page requires login on every page so it will work fine).

That's is where my problem is. I need to take id from my cookies (1 for example) and use it to go to profile/1.php.

Since my navigation bar is made with HTML, I need to use href system to redirect, but href cant recognize code from PHP $id.

I tried to make separated redirect file but that gave me Cannot modify header information error.

Is there a way for me to make such mess work (just learning) or do I need to scrap that idea?

  • 写回答

1条回答 默认 最新

  • dqmgjp5930 2018-08-30 12:53
    关注

    but href cant recognize code from PHP ($id).

    You just start the PHP tag inside the href like so

    <a href="profile/<?= $id ?>.php">My profile</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题