如何使用PHP或jQuery隐藏文本
我有一个脚本代码,可以使用AJAX在imgur上上传照片。但我无法隐藏公众的客户ID 我想我需要使用PHP来实现这一点,使用以下代码:如何使用PHP或jQuery隐藏文本,php,jquery,Php,Jquery,我有一个脚本代码,可以使用AJAX在imgur上上传照片。但我无法隐藏公众的客户ID 我想我需要使用PHP来实现这一点,使用以下代码: <?php $idClient = "abc12abc12abc"; echo $idClient ; ?> 但在查看其源代码时,客户端ID仍然可见 以下是完整的代码: <!DOCTYPE html> <html> <head> <meta http-equiv=
<?php $idClient = "abc12abc12abc";
echo $idClient ;
?>
但在查看其源代码时,客户端ID仍然可见
以下是完整的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Imgur Upload Test</title>
<style>
#image_preview, #image_preview_2 {
max-width: 200px;
}
</style>
</head>
<body>
<h1>Imgur Upload Test</h1>
<input type="file" id="image_selector" />
<div id="image_preview"></div>
<h2>Image On Imgur:</h2>
<div id="image_preview_2"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$("#image_selector").change(function() {
var reader = new FileReader();
reader.onload = function(e) {
var data = e.target.result.substr(e.target.result.indexOf(",") + 1, e.target.result.length);
$("#image_preview").html("<img src='" + e.target.result + "' />");
$.ajax({
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID <?php $idClient = "abc12abc12abc";
echo $idClient ;?>'
},
type: 'POST',
data: {
'image': data,
'type': 'base64'
},
success: function(response) {
$("#image_preview_2").html("<img src='" + response.data.link + "' />");
}, error: function() {
alert("Error while uploading...");
}
});
};
reader.readAsDataURL(this.files[0]);
});
</script>
</body>
</html>
Imgur上传测试
#图像预览,图像预览2{
最大宽度:200px;
}
Imgur上传测试
Imgur上的图像:
$(“#图像_选择器”).change(函数(){
var reader=new FileReader();
reader.onload=函数(e){
var data=e.target.result.substr(e.target.result.indexOf(“,”)+1,e.target.result.length);
$(“#图像预览”).html(“”);
$.ajax({
网址:'https://api.imgur.com/3/image',
标题:{
“授权”:“客户端ID”
},
键入:“POST”,
数据:{
“图像”:数据,
“类型”:“base64”
},
成功:功能(响应){
$(“#图像_预览_2”).html(“”);
},错误:函数(){
警报(“上传时出错…”);
}
});
};
reader.readAsDataURL(this.files[0]);
});
解决方案是什么?从ajax中点击php脚本,然后从php脚本中点击带有auth头的imgur。如果您在控制台中检查请求,它仍然可见。这是因为你在客户端需要它。。。因此,无论您做什么,它都会以某种方式可见。@BasvanStein不,如果php脚本使用curl调用API,那么它对客户端不可见。在我当前的项目中,我使用(使用curl)Yes ok做了类似的事情,如果您只将客户机id添加到php脚本中,true.ALL-意味着无法隐藏公共的客户机id?