doushui5587 2016-11-16 23:27
浏览 32
已采纳

防止流量绕过目标网页[关闭]

I have a website where, when visitors land on any of a several landing pages (different languages), they are given an opportunity to enter any of a number of promotion codes into a form. If they enter one of the correct codes (stored on a SQL table), they go to another page with a form where they can give their mailing info to receive a free product. If the code they entered isn't on the table, they get a message the code they entered is invalid and are blocked.

This works through php. When the landing page form is entered and submitted, a URL something like this: website.com/formentry.php?promo=code is generated where 'code' matches whatever the user entered into the form. If “code" matches a string in the code column in the database table, they get sent to the entry form. If it doesn’t, they get blocked. To this point, everything works great and has been running smoothly for months.

However a problem has been identified recently: The landing pages can be circumvented by entering website.com/formentry.php?code=code directly into a browser’s URL field. This is a problem for several reasons and I need to prevent it from being possible.

Does anyone have any ideas for a solution; perhaps using the .htaccess file to send those URL requests back to the landing page?

  • 写回答

3条回答 默认 最新

  • duanshangying5102 2016-11-16 23:47
    关注

    Using sessions, you can set the user's session when they enter the correct code on the landing page:

    session_start();
    $_SESSION[valid_user] = true;
    

    Then, on every other page (non-landing-page), you put a validator like:

    if (!$_SESSION[valid_user])
    {
      echo "You do not have permission to view this page";
    }
    

    Or, instead of showing an error message, you can redirect the user to another page:

    if (!$_SESSION[valid_user])
    {
      $url = "http://example.com";
      header("Location: $url");
      exit();
    }
    

    If you want to take this one step further, let's say the auth. code is 420. You can set the landing page to take the submitted code and set

    $_SESSION[420] = true;

    and on the page for product #420, or whatever, validate, as above, that the user's session contains 420 == true. That way, if they use coupon code 420, they're only authorized to see product #420's page, not all product pages.

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

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了