gpt4 book ai didi

javascript - php 文件上的安全 angularjs 代码 ajax 请求

转载 作者:行者123 更新时间:2023-12-02 15:30:49 25 4
gpt4 key购买 nike

我正在开发网络应用程序,并且正在使用 angularjs。问题是,我希望能够保护我的 Angular 代码,我不希望有人查看我的代码。

我已将我的 Angular 代码放入 php 文件,并且我正在尝试通过 $.ajax() 方法发出请求。

你能帮我吗?

这是代码:

index.html 文件

<!doctype html>
<html lang="en">
<head>
..............
</head>
<body>
..............
<script src="assets/plugins/bootstrap/js/tooltip.js"></script>
<script src="assets/plugins/bootstrap/js/popover.js"></script>
<script src="assets/plugins/wow/wow.min.js"></script>
<script src="assets/plugins/pouchdb/pouchdb-4.0.0.min.js"></script>

<!-- Sripts for individual pages, depending on what plug-ins are used -->
<script src="assets/plugins/layerslider/js/greensock.js" type="text/javascript"></script>
<script src="assets/plugins/layerslider/js/layerslider.transitions.js" type="text/javascript"></script>
<script src="assets/plugins/layerslider/js/layerslider.kreaturamedia.jquery.js" type="text/javascript"></script>
<!-- Initializing the slider -->

<!--Angular scripts-->
<script src="assets/plugins/angular/angular.min.js"></script>
<script src="assets/plugins/angular-country-select/angular.country-select.js"></script>
<script>
(function(){
$.ajax({
url: 'assets/js/an.app.php',
type:'GET',
cache: false,
success: function(newScript){
if(newScript){
$('body').append(newScript);
console.log(newScript);
}
}
});
})();
</script>
<!--Fin Angular-->
<script>
jQuery("#layerslider").layerSlider({
pauseOnHover: true,
autoPlayVideos: false,
skinsPath: 'assets/plugins/layerslider/skins/',
responsive: true,
skin: 'borderlessdark3d',
hoverPrevNext: true,
});
</script>

<script>
new WOW().init();
</script>

<!-- Boomerang App JS -->
<script src="assets/js/wp.app.js"></script>
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</body>
</html>

assets/js/an.php

<?php
$referer = $_SERVER['HTTP_REFERER'];
// Check URL
if ( $referer == 'http://localhost/netskools_website/' || $referer == 'http://localhost/netskools_website/sign-up.html' || $referer == 'http://localhost/netskools_website/index.html') {
?>
<script type="text/javascript">
(function () {
'use strict';

var MyApp = angular.module('MyApp', ['countrySelect']);
//Directive menu principal de pages
MyApp.directive('mainmenu', [function () {
return {
restrict: 'E',
templateUrl: 'assets/ngapp/mainmenu.html'
};
}]);
// Directive Template de téléchargement en banière
MyApp.directive('maindownload', [function () {
return {
restrict: 'E',
templateUrl: 'assets/ngapp/maindownload.html'
};
}]);
// Directive Footer de pages
MyApp.directive('thefooter', [function () {
return {
restrict: 'E',
templateUrl: 'assets/ngapp/footer.html'
};
}]);
//
MyApp.controller('homeController', ['$scope', function ($scope) {
$scope.activepage = "home";
}]);
//
MyApp.controller('signupController', ['$scope', '$q', '$filter', function ($scope,$q,$filter) {
$scope.activepage = "nous-contacter";
$scope.state_activation = false;
$scope.nom="";
$scope.prenom="";
$scope.email="";
$scope.type_hote="";
$scope.selectdefault=0;
$scope.selectedCountry="";
$scope.nom_hote="";
$scope.etat_region="";
$scope.ville="";
$scope.adresse="";
$scope.telephone="";
$scope.info="";

$scope.enable_submit = function () {
if ($scope.subscription === true) {
$scope.state_activation = true;
} else {
$scope.state_activation = false;
}
return $scope.state_activation;
};

//Initialisation de la base données
var netskoolsSouscriptionsDB, ddoc;
netskoolsSouscriptionsDB = new PouchDB('http://kristdev:Kokodi.1@localhost:5984/netskools_souscriptions');
// ====================

// create a design doc
ddoc = {
_id: '_design/indexCollection',
views: {
indexCollection: {
map: function mapFun(doc) {
if (doc.collection) {
emit(doc.collection);
}
}.toString()
}
}
};
// =======================


// Save Design Doc
netskoolsSouscriptionsDB
.put(ddoc)
.then(function (response) {
// handle response
console.log(JSON.stringify(response));
})
.catch(function (err) {
console.log(err);
});
/*============================*/

//Ajout des données du formulaire
$scope.addData = function() {
if($scope.nom,$scope.prenom,$scope.prenom,$scope.type_hote,$scope.nom_hote,$scope.selectedCountry,$scope.etat_region,$scope.ville,$scope.adresse,$scope.telephone,$scope.info){
var deferred = $q.defer();
var value_hote;
switch (true){
case $scope.type_hote == 0:
value_hote = 'Ecole primaire';
break;
case $scope.type_hote == 1:
value_hote = 'Ecole secondaire';
break;
case $scope.type_hote == 2:
value_hote = 'Ecole supérieure';
break;
case $scope.type_hote == 3:
value_hote = 'Ecole de formation';
break;
case $scope.type_hote == 4:
value_hote = 'Institut de recherche ou de statistique';
break;
case $scope.type_hote == 5:
value_hote = 'Organisme ou organe étatique';
break;
default: value_hote = 'Autre structure';

}

var doc = {
collection: 'demandeur',
nom: $scope.nom,
prenom: $scope.prenom,
email: $scope.email,
type_hote: value_hote,
nom_hote: $scope.nom_hote,
pays_residence: $scope.selectedCountry,
etat_region: $scope.etat_region,
ville: $scope.ville,
adresse: $scope.adresse,
telephone: $scope.telephone,
info: $scope.info,
activation: false,
_id: new Date().toISOString()
};

netskoolsSouscriptionsDB
.put(doc)
.then(function (response) {

// handle response
console.log('Chaine Ecrite: ' + JSON.stringify(response));
document.getElementById('nom').value='';
document.getElementById('prenom').value='';
document.getElementById('email').value='';
document.getElementById('prenom').value='';
document.getElementById('nom_hote').value='';
document.getElementById('etat_region').value='';
document.getElementById('ville').value='';
document.getElementById('adresse').value='';
document.getElementById('telephone').value='';
document.getElementById('info').value='';
swal('Demande enregistrée avec succès!', 'Un de nos télé-conseillers vous contactera dans les 48h', 'success');
$scope.state_activation = false;
deferred.resolve('Ecriture réussie');
})
.catch(function (err) {
console.log(err);
deferred.reject('Echec Ecriture');
});
return deferred.promise;
}else{
ohSnap('Remplissez le formulaire', 'red');
}
};
/*====================================*/
}]);
})();
</script>
<?php
}else echo "Vous n'avez pas accès à cette page";
?>

最佳答案

简单地通过ajax加载 Angular 资源,例如 Controller 或其他模块是不切实际的。一个简单的理解是,所有模块都应该在文档准备好(document.ready)之前加载。但是你在事件发生后通过ajax加载资源。

如果您确实想通过限制 HTTP 引荐来源网址 来保护您的代码,您只需添加一个 script 标记,并链接到 php 文件。像这样:

<script src="assets/js/an.app.php"></script>

您的 php 文件不需要更改。但添加 header 更好:

// assets/js/an.php
<?php
header('Content-type: application/javascript');
$referer = $_SERVER['HTTP_REFERER'];
// Check URL
if ( $referer == 'http://localhost/netskools_website/' || $referer == 'http://localhost/netskools_website/sign-up.html' || $referer == 'http://localhost/netskools_website/index.html') {
?>

// rest of your code

关于javascript - php 文件上的安全 angularjs 代码 ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33331599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com