将html URL参数传递给PHP脚本

将html URL参数传递给PHP脚本,php,jquery,html,ajax,.htaccess,Php,Jquery,Html,Ajax,.htaccess,这是我第一周使用php,所以提前感谢您的建设性回复 我有一个附加了url参数的html页面:mywebsite.com/f.html?survey_id=5D86055F35BF41F3A353F2C779FC478DC 我需要将这个survey_id参数传递给一个php脚本,该脚本将这个id保存在一个文本文件中。由于文本文件为空,我当前的代码传递不正确 html页面是/f.html php脚本是/test.php 这一切都是在服务器端运行的 保存脚本可以正常工作,就好像我只保存了一个类似“d”

这是我第一周使用php,所以提前感谢您的建设性回复

我有一个附加了url参数的html页面:mywebsite.com/f.html?survey_id=5D86055F35BF41F3A353F2C779FC478DC

我需要将这个survey_id参数传递给一个php脚本,该脚本将这个id保存在一个文本文件中。由于文本文件为空,我当前的代码传递不正确

html页面是/f.html php脚本是/test.php

这一切都是在服务器端运行的

保存脚本可以正常工作,就好像我只保存了一个类似“d”的字符串而不是$id一样,一切都正常工作

我已经使用$\u GET尝试了下面的代码,但是输出是空的,所以我假设参数没有被传递到执行fwrite的.php脚本

我还了解到,这可能通过修改.htaccess文件来解决,并尝试将以下内容添加到我的.htaccess文件中,但没有解决问题

重写规则“/pages/(.+)”“/page.php?page=$1”[QSA]

我觉得这不完全是正确的规则,但不知道如何修改它,以适应我的具体情况

jQuery(document).on('click', 'div#download', function () {
    jQuery('div#counter1').html('Loading...');
    var ajax = jQuery.ajax({
        method: 'get',
        url: '/test.php', // Link to this page
        data: { 'increase': '1' }
    });
    ajax.done(function (data) {
        jQuery('div#counter1').html(data);
    });
    ajax.fail(function (data) {
        alert('ajax fail : url of ajax request is not reachable');
    });
});
test.php

  $myFile = "testFile2.txt";
  $fh = fopen($myFile, 'w') or die("can't open file");
  $id = $_GET['survey_id'];
  $stringData = $id;
  fwrite($fh, $stringData);
  fclose($fh);
文本文件中的预期结果应为5D86055F35BF41F3A353F2C779FC478DC


当前结果是文本文件为空。

在数据中传递调查id,如下所示

 jQuery(document).on('click', 'div#download', function () {
var url =window.location.search;
    var survey_id = /survey_id =([^&]+)/.exec(url)[1];


        jQuery('div#counter1').html('Loading...');
        var ajax = jQuery.ajax({
            method: 'get',
            url: '/test.php', // Link to this page
            data: { 'increase': '1', 'survey_id': survey_id }
        });
        ajax.done(function (data) {
            jQuery('div#counter1').html(data);
        });
        ajax.fail(function (data) {
            alert('ajax fail : url of ajax request is not reachable');
        });
    });

您还必须将调查id传递到test.php页面。@reflon是的,这就是我要问的。您调用test.php的唯一参数是
增加
-因此您当然不能期望
$\u GET['survey\u id']
在其中有任何值。您在HTML页面上运行的JS代码必须读取此值,并将其传递…因此,您的问题归结为另一个副本,然后…?如果只有1个参数,则此副本可能有效,但如果在survey_id后面有更多参数,则会失败。这是有效的!谢谢。正如@Refilon所指出的,我只有一个参数