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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line