简体   繁体   English

相同的PHP变量具有2个不同的值

[英]Same PHP variable having 2 different values

I'm making a simple site using a local apache webserver with cgi so I can run my python scripts. 我正在使用带有cgi的本地apache网络服务器创建一个简单的站点,因此我可以运行python脚本。 I also am using jQuery to make AJAX requests to the python scripts so I can run the script asynchronously. 我还使用jQuery向python脚本发出AJAX请求,以便可以异步运行该脚本。 I'm also using PHP to simulate a login button so users can login to the website. 我还使用PHP模拟登录按钮,以便用户可以登录网站。 Problem is that after the users logs in, it displays the ID of the user, and I want this same ID to be passed to the python script as a parameter, where the script will take it and return something else. 问题是用户登录后,它会显示用户的ID,并且我希望将此ID作为参数传递给python脚本,脚本将在其中获取它并返回其他内容。 Although I'm using the same exact PHP variable, the variable I'm passing to the python script is similar, but not the same as the one it displays when the user logs in. 尽管我使用的是完全相同的PHP变量,但我传递给python脚本的变量却相似,但与用户登录时显示的变量不同。

PHP Code to display ID after user logs in: 用户登录后显示ID的PHP代码:

echo "Welcome back" . "</br> </br>" . $picture ."</br>". $steamprofile['personaname'] . "</br>" .$state .  "</br>".  "Steam ID: ". $steamprofile['steamid'] . "</br>";
    echo '<a href="' . $url . '">Steam Profile</a>'  . "</br> </br>" . "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>";

PHP Variable that's passed to python script (using J 传递给python脚本的PHP变量(使用J

$(document).ready(function(){
    $("#steambutton").click(function() {
        $.ajax({
            type: "POST",
            url: "http://localhost/cgi-bin/Steap.py",
            data: {steamid: <?php echo $steamprofile['steamid']?>},
            success: function(response) {
                $("#steamdiv").html(response);  
            }
        });
    });
});
</script>

As you can see in both code snippets the variable that's having two different values is the $steamprofile['steamid'] . 如您在两个代码段中所见,具有两个不同值的变量是$steamprofile['steamid'] These two code snippets as almost next to each other, and I don't change the value of $steamprofile['steamid'] anywhere after the first script is executed. 这两个代码片段几乎彼此相邻,在执行第一个脚本之后,我不会在任何地方更改$steamprofile['steamid']的值。 Why is this happening? 为什么会这样呢? It seems really weird for the variable to have two similar values. 变量具有两个相似的值看起来真的很奇怪。

As an example, this is the ID of the user after they login (from the first code): 76561198041778794 例如,这是用户登录后的ID(从第一个代码开始): 76561198041778794

This is the ID that's passed to the python script from the second code, however: 76561198041778800 这是从第二个代码传递给python脚本的ID,但是: 76561198041778800

尝试以下方法传递数据(添加引号将其作为字符串传递):

data: {steamid: "<?php echo $steamprofile['steamid']?>"},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM