dongli4711 2013-01-21 11:00
浏览 68
已采纳

在URL中保留一个GET变量

I have a bit of an odd question, I'm sure most of you realise that these sorts of questions arise out of certain situations that a developer has no control over!

I would like to work out how to keep a querystring parameter in the URL at all times. If the parameter is not set, I'd like a default to be appended to the URL ?param=something

I asked a previous question relating to this and have been able to use htaccess to add a default query - but this only works fir the initial request whereas I need to ensure it is always present in the address.

I am thinking of using a cookie - set with PHP and then queried with .htaccess.

So, I am asking if this is possible and if there is a better way of doing this?

  • 写回答

4条回答 默认 最新

  • doumo0206 2013-01-21 11:40
    关注

    Without changing all the URLs I can't see this being possible and as discussed it is a very hacky way to do it.

    I would suggest you give them a "special" button that they use for copying a link. Make them use this button to copy the link instead of the URL. You can then control the data properly without hacking the website.

    Edit: You "could" add some JQuery in to append ALL links with your param. Have you thought about this?

    $(document).ready(function() {
      $('a[href]').each(function() {
        this.href = this.href + '?something=<?php echo $_SESSION["myparam"]; ?>'
      });
    });
    

    You could get the param from the initial page load / session but this would require your users to have JS enabled (Which most people do now).

    p.s Untested semi-pseudo code. I can test it properly if you decide to go down this route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)