Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 如何给 form 加 token #7

Open
kitewhere opened this issue May 2, 2018 · 0 comments
Open

php 如何给 form 加 token #7

kitewhere opened this issue May 2, 2018 · 0 comments

Comments

@kitewhere
Copy link
Owner

kitewhere commented May 2, 2018

#1 手动指定

<form>
<?php echo token(); >
</form>

#2 自动添加

#2.1 自己写正则或解析 html 找到 form 再插入 token

#2.2 output_add_rewrite_var

<?php
output_add_rewrite_var('token','value');

echo '<form><input type="text" /></form>';
//  <form><input type="hidden" name="token" value="value"><input type="text" /></form>

output_add_rewrite_var 可以重写 url 添加 query 但是有有几点需要注意

  1. 只对相对路径生效 http://www.aaa.com/aaa.html 无效
  2. 作为 url query 添加的会按照 rawurlencode 编码
  3. 作为 form hidden 添加的会按照 htmlentites 编码
  4. 能添加的 tag 受 ini 配置 url_rewriter.tags 控制 默认 只有 ‘form=’ 如果想也给 a 标签 添加 需要 赋值为 ’form=,a=href‘
  5. 也可以使用自定义的属性名 比如 <a data-url="aaa.php"> 设置 url_rewriter.tags 为 "a=data-url" 即可 但 一个标签只能有一个 即 href 会失效

参考

从php的缓冲区说起
深入理解php的输出缓冲区

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant