Je crée un site Web de commerce électronique pour mon travail de projet. Dans lequel j'ai créé une page application.cfm, en utilisant le code de this tutorial:Comment créer une connexion pour la zone membre seulement
<!--- Create the application --->
<cfapplication name="MyApp"
clientmanagement="Yes"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0,0,0,10)#"
applicationtimeout="#CreateTimeSpan(0,0,0,10)#" />
<!--- Now define that this user is logged out by default --->
<CFPARAM NAME="session.allowin" DEFAULT="false" />
<!--- Now define this user id to zero by default, this will be used later on to access specific information about this user. --->
<CFPARAM NAME="session.user_id" DEFAULT="0" />
<!--- Now if the variable "session.allowin" does not equal true, send user to the login page --->
<!--- the other thing you must check for is if the page calling this application.cfm is the "login.cfm" page and the "Login_process.cfm" page since the Application.cfm is always called, if this is not checked the application will simply Loop over and over. To check that, you do the following call --->
<cfif session.allowin neq "true">
<cfif ListLast(CGI.SCRIPT_NAME, "/") EQ "loginn.cfm">
<cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "login_process.cfm">
<cfelse>
<!--- this user is not logged in, alert user and redirect to the login.cfm page --->
<script>
alert("You must login to access this area!");
self.location="loginn.cfm";
</script>
</cfif>
</cfif>
Ceci est la page Login_process.cfm:
<!--- Get all records from the database that match this users credentials --->
<cfquery name="qVerify" datasource="cfdb2">
SELECT User_name, User_pass
FROM uid_pass
WHERE User_name = '#name#'
and User_pass='#pass#'
</cfquery>
<cfif qVerify.RecordCount>
<!--- This user has logged in correctly, change the value of the session.allowin value --->
<cfset session.allowin = "True" />
<cfset session.User_name = qVerify.User_name />
<!--- Now welcome user and redirect to "<strong>members_only.cfm</strong>" --->
<script>
alert("Welcome user, you have been successfully logged in!");
self.location="index.cfm";
</script>
< cfelse>
<!--- this user did not log in correctly, alert and redirect to the login page --->
<script>
alert("Your credentials could not be verified, please try again!!!");
self.location="Javascript:history.go(-1)";
</script>
</cfif>
Le problème que je suis confronté avec le code est quand je ouvrir la page d'index, il me demande de vous connecter. Sans me connecter, je ne peux pas continuer. Si j'ouvre la page registration.cfm directement, la même chose arrive. Comment puis-je structurer le code de sorte qu'un invité puisse accéder aux choses, mais doit se connecter quand il utilise l'option "Ajouter au panier".
Arrêtez d'utiliser Application.cfm, commencez à utiliser Application.cfc. –