少女祈禱中...
Loading...
图片加载过慢?试试 从源站加载资源 X

ccloli

一个炒鸡坑的 url 短链 php =.=

其实这货已经弄好很久了 =.= 虽然已经弄好了,不过 bug 还不是一般的多啊……算了不管它了,先发上来凑凑字数吧 =.=……

其实本来有考虑过不依托数据库的,不过貌似不这样就不好去重……而且用 txt 保存数据调用略麻烦,建立文件夹管理略麻烦,所以还是只能用 mysql 了……

由于本人技术过渣,请手动配置……

  1. 通过 phpmyadmin 等程序在数据库中新建一个表,表名随意(此处以 sheet 为例),然后设置如下结构:
    字段:surl,类型:TEXT,整理:utf8_general_ci
    字段:lurl,类型:TEXT,整理:utf8_general_ci
  2. 保存后将后面提到的两个文件上传到网站的根目录下
  3. 设置 .htaccess 文件如下(其实就是 WordPress 的 htaccess OTL):

然后是那两个文件……

首先肯定是前台页……前台页既担当着导航的功能,也担当着跳转页面的功能……获取短链 url 的方式是将当前用户提交的 url 提交至 add/index.php 下,然后通过 XMLHttpRequest 获取数据……至于前台页的美化我就不管了 =.= 将该文件放于站点根目录……

之后是后台处理页……后台在接收到数据后会连接数据库,同时生成一个四位随机字符备用。如果提交的 url 已经存在,则直接返回短链,否则写入数据库生成新的短链;而如果提交的自定义短链 url 已经存在,则会用生成的四位随机字符生成新的短链 =.= 将该文件放于根目录下 add 文件夹……

目前已知 bug……

  1. 不支持中文 =.=
  2. 可能不支持大小写区分
  3. 可能会出现生成的随机字符冲突问题
  4. 设置较长的自定义短链接可能会出现用随机字符做短链的问题
  5. ……想不出来了_(:з」∠)_

预览效果……

  1. 864907600cc说道:

    顺便数一下那些准备发布但目前已经放置 play 的项目吧 _(:з」∠)_
    1. 福利发布平台(已完成 95%,已放置 3 个月以上)
    2. crxcheck(已完成,已放置 2 个月以上)
    3. 新版 BGM 样式(已完成 85%,已放置 2 周)
    4. 原定今天发布的某张无节操抠图,结果忘了_(:з」∠)_(已被 PS 的快速选择工具坑到导致出现锯齿,已放置 3 天)

    Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
    1. Jak Wings说道:

      @864907600cc 图片有锯齿就尝试在轮廓那加点阴影过渡吧。

      短链不支持中文是因为没有 rawurldecode() ,接收的都是 %xx 么?
      太长的不叫短链当然要截短了。
      那个 .$url. 表示 addslashes() 后的链接么?→_→

      Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
      1. Jak Wings说道:

        @Jak Wings 假如 PHP 支持 mb_* 函数,可以用来数中文的长度。

        Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
        1. 864907600cc说道:

          @Jak Wings 图片有锯齿果断截原图拼上去 ← ← 没有设置好快速选择工具,后来用套索工具一步步抠图就没事……

          是的,接收的都是 %xx / \ 但是我没有设置长度限制啊……其实这货实际上只是个自动重定向页面的程序而已……

          $url 没有用 addslashes 转义,直接提交的 / \

          mb_api?我觉得 subdomain 的服务器没有这么高级 =.=

          Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
          1. Jak Wings说道:

            @864907600cc http://www.php.net/manual/en/function.mb-strlen.php
            可以用探针看看。
            长度限制只是限制创建的短链~

            Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
            1. 864907600cc说道:

              @Jak Wings 不管它了,不想填坑了 / \

              Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
              1. Jak Wings说道:

                @864907600cc (╯-_-)╯╧╧

                Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
                1. 864907600cc说道:

                  @Jak Wings 桌子是无辜的 0.0

                  Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
                2. 864907600cc说道:

                  @Jak Wings 话说 GMail 的限制真烦 =.=

                  Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
                  1. Jak Wings说道:

                    @864907600cc 桌子接住~
                    邮件提醒的样式又改了 -_- GMail 啥限制?图片么?

                    Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
                    1. 864907600cc说道:

                      @Jak Wings 被砸死了 X_X
                      style 标签清空就算了,HTML 5 标签也会被清,box-shadow、background、position css 属性也会被清,真心无奈← ←

                      Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
                  2. Jak Wings说道:

                    @864907600cc background 还在啊 →_→ 只是没图片……

                    Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
                    1. 864907600cc说道:

                      @Jak Wings 其实标准样式应该是一个渐变条纹……

                      图片是 Gravatar 的……

                      Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
                  3. Jak Wings说道:

                    @864907600cc 好难看的条纹 ;→ →

                    Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
                    1. 864907600cc说道:

                      @Jak Wings 本来想要斜线的,该死的 chrome 渲染有问题

                      Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
                  4. Jak Wings说道:

                    @864907600cc Gmail CheckerPlus 扩展上不带图片的显示,好看多了:http://uploadpie.com/BBZEl

                    Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
  2. 天羽ちよこ说道:

    qq.my是个啥东西

    Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
    1. 864907600cc说道:

      @天羽ちよこ 一个域名,不过现在貌似无法解析了

      Google Chrome 29.0.1547.62 Google Chrome 29.0.1547.62 Windows 7 x64 Edition Windows 7 x64 Edition
      1. 天羽ちよこ说道:

        @864907600cc 我这打开正常……Sun Java™ System Web Server 7.0

        Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
      2. 天羽ちよこ说道:

        @864907600cc 原来你说的是太过虚幻….

        Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
  3. 天羽ちよこ说道:

    难道没有正则来验证url是否合法么…..

    Google Chrome 30.0.1599.28 Google Chrome 30.0.1599.28 GNU/Linux x64 GNU/Linux x64
    1. 864907600cc说道:

      @天羽ちよこ 不想填坑了 / \

      Google Chrome 31.0.1621.1 Google Chrome 31.0.1621.1 Windows XP Windows XP
      1. 千与琥珀说道:

        @864907600cc (ノ=Д=)ノ┻━┻ (ノ*・ω・)ノ

        Google Chrome 29.0.1547.66 Google Chrome 29.0.1547.66 Windows 7 Windows 7
  4. 千与琥珀说道:

    php有专门的函数来判断url是否合法,首先用parse_url()分解url在用filter_validate_url()来验证url是否合法,再用get_headers()判断200头来确定文件是否存在,只有经过这样的判断之后才算是一个合法的url
    测定长度可以urlencode()后用strlen来判断

    此外,你完全可以用域名的md5来算出唯一的值来做随机,而且保证不会重复

    html_mail的标准还停留在03年前的标准,太复杂的阅读器是解析不了的

    中文的是带编码的函数 例如 太过虚幻.com.nu=xn--sssq7j484b04h.com.nu,路径的编码要用urldecode()或rawurldecode()来解码才能正确解析

    Google Chrome 29.0.1547.66 Google Chrome 29.0.1547.66 Windows 7 Windows 7
  5. 雪见仙尊说道:

    cc大神,你这个大腿我抱定了←_←在http://acger.moe/看到你的回复我跟着到这里来了

    Google Chrome 39.0.2171.95 Google Chrome 39.0.2171.95 Windows 7 x64 Edition Windows 7 x64 Edition
  6. 7IN0SAN9说道:

    用 ID 十进制转换成 base32 或者其他什么东西比用随机字符要好

    Google Chrome 48.0.2564.116 Google Chrome 48.0.2564.116 Mac OS X  10.11.3 Mac OS X 10.11.3
    1. 864907600cc说道:

      很久以前写的玩意了,当时也并没有考虑那么多(其实像其他的短链工具那样按 ID 来排就是最简单的解决方式了

      Google Chrome 47.0.2526.111 Google Chrome 47.0.2526.111 Windows 8.1 x64 Edition Windows 8.1 x64 Edition

Jak Wings进行回复 取消回复