Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 7 IBS 685. Displaying an Image using CFOUTPUT 1.Save images in a folder under wwwroot directory 2.Create a database column and name it e.g. imagefilename.

Similar presentations


Presentation on theme: "Week 7 IBS 685. Displaying an Image using CFOUTPUT 1.Save images in a folder under wwwroot directory 2.Create a database column and name it e.g. imagefilename."— Presentation transcript:

1 Week 7 IBS 685

2 Displaying an Image using CFOUTPUT 1.Save images in a folder under wwwroot directory 2.Create a database column and name it e.g. imagefilename Make sure that imagefilename column’s datatype is “Text” 3.Create a query that selects the imagefilename column 4.Create a img src tag where you want to display the image 5. Create a CFOUTPUT tag to display the image 6. The alt tag can be dynamic too. You can output the definition of the image if you have the information in your database.

3 The structures of the email (such as the recipient list, the subject line and sender) is specified in attributes to the CFMAIL tag. The content of the message is placed between opening and closing CFMAIL tags. The critical attributes used in the CFMAIL tag are: To: specifies the email address of the recipients From: Specifies the content of the From line of the message Subject: Specifies the Subject line of the email

4 CFMAIL Example <CFMAIL to=someone@some.domain From=thesender@another.domain Subject=“A sample Coldfusion E-mail” This is my test message Type:Specifies the content type of the message Server: Specifies an alternate SMTP mail server. By default, the mail server specified in the CF administrator is used for sending outgoing messages

5 CFMAIL <CFMAIL TO="recipient“ FROM="sender" SUBJECT="msg_subject" TYPE="msg_type" MIMEATTACH="path“> Before you can use the tag to send email messages, you need to specify a mail server in the CF Administrator.

6 Generating Email from the Contents of a Form Send a Greeting Send a Greeting Use the following form to send a greeting to a friend by e-mail Your Friend's E-mail Address: Your Name:

7 Sending Your Greeting <CFMAIL TO="#Form.to#" FROM="bozdogan@mercy.edu" SUBJECT="A Greeting">Hi! This is a quick, computer-generated greeting sent to You courtesy of #Form.name# and the CFMAIL tag. Message Sent Your message to #Form.to# has been sent Oops You need to provide an E-mail address for the recipient. Hit the Back button to return to the form and provide one. Thanks. Generating Email from the Contents of a Form

8 Structures Structures are the most powerful data type in Coldfusion. Structures provide a way to store data within data.

9 Structures email: #contact.firstname# #contact.lastname# ---> #StructCount(contact)#

10 p.175 Is an invaluable diagnostics and debugging tool capable of displaying all sorts data in a clean and easy to read format.

11 Introducing Web Application Framework

12 WAF Features all have to do with making all your CF pages for a particular site behave as if they were related to one another –that is to make them behave a single application.

13 WAF The Web application framework is designed to help you with the following: –Consistent look and feel –Sharing variables between pages So far the variables that you have worked all “die” when each page request has been processed. Variety of ways to maintain the values of variables between page requests.

14 WAF The framework is the force that binds your templates together.

15 Using Application.cfm To get started with the WAF, you first must create a special file called Application.cfm. This file is just an ordinary CF template. Only two things make Application.cfm special: –The code in your Application.cfm file will be automatically included just before any of your pages –You cant visit an Application.cfm directly. You will receive an error message from CF.

16 Application.cfm File(page 382) CF looks for an Application.cfm file in the directory of the called page. –If not found in the current directory, CF will continue to search the directory structure for a file named Application.cfm –If found, the Application.cfm file will be included at the top of the page –If not found, CF continues processing the page without it.

17 Listing 16.1 Application1.cfm <!--- Filename: Application.cfm (The "Application Template") Created by: Nate Weiss (NMW) Please Note: All code here gets executed with every page request!! Purpose: Sets "constant" variables and includes consistent header ---> You can refer to this variable as the datasource attribute for all the tags in the application, as in datasource=“#datasource#”

18 Using Application.cfm #CompanyName#

19 OnRequestEnd.cfm (page 385) Automatically included at the very end of every page request, rather than at the beginning. This file cannot be visited directly CF looks for OnrequestEnd.cfm in the same folder as application.cfm Place OnrequestEnd.cfm in the same location in which your Application.cfm is sitting.

20 OnRequestEnd.cfm

21 Another Example (c) #year(Now())# #CompanyName#. All rights reserved.

22 Working with Sessions( Page 417) WAF focusing on the features that let you track variables on a per-user basis. This opens up all kinds of opportunities for keeping track of what each –user needs, –wants, –has seen –or interacting with.

23 The Web's Statelessness Page 417 HTTP creates a new connection for every page request –Variables and flags set during one request are not available for the next request Work around this problem by using: –Cookies –Application framework –Session variables

24 Solutions Provided by ColdFusion CF provides three types of variables that help you maintain the state of a users visit from page to page and between visits. –Cookies –Client Variables –Session Variables

25 HTTP Cookie Variables Cookies are simple variables that can be stored on a client machine. Browsers store cookies in a physical file or files on the client machine. Once the browser has a cookie set, each and every HTTP request will retrieve all cookies for the requested web server domain.

26 If the user requests a page from the Macromedia domain, all cookies for that domain would be sent in the HTTP header to the web server. Once the browser send the cookies via the HTTP header, CF has access to all of these cookies at runtime. HTTP Cookie Variables

27 Cookies are: –Domain specific-set and retrieved for specific servers. –Sent to the Web server with every HTTP request –Persistent-they remain stored in the browser until expired or deleted –Limited to 20 per domain and 4 K worth of information.

28 Cookie Uses Cookies are used to obtain information about a user between and within browser sessions. Use of cookies include: –Storing a unique identifier as a cookie, so that information such as shopping cart data is identified to the browser session. –Storing a session information, such as a flag that they are logged in until the browser is closed. –Storing user preferences, so they might return to the site and have the same look and feel.

29 Making Cookies CF allows you to create cookie by using tag. The most common reason for using is to control how long the cookie will live before before it expires. To set a cookie with user_ID with value of 2344: –

30 Cookie Types There are two types of cookies you can create: Persistent cookies Session cookies Both can be created using the tag Differentiated by the use of the EXPIRES attribute.

31 Persistent vs. Session Cookies Persistent Cookies: –EXPIRES attribute determines when the cookie gets deleted from the browser machine: EXPIRES = "n" EXPIRES = "date" EXPIRES = "never" EXPIRES = "now"

32 Session Cookies Created by omitting the EXPIRES attribute from the tag Only valid until all the browser sessions on that client machine are closed Use this value when you only want to track the user for the current session Destroyed when the browser sessions close, and are never stored in a file on the browser machine

33 Accessing Cookies Since HTTP specifies that all cookies be automatically sent to the requesting Web server domain, you do not need to fetch them. You would access a cookie simply by using it and prefixing it with the Cookie prefix. –The user_ID is: – #cookie.user_ID#

34 Because cookies are physical files stored on the browser computer that can be deleted at will, you should always test for the existence of cookies prior to use. –Test for existence using the IsDefined () function The user ID is: #cookie.user_ID# Accessing Cookies

35 Session Variables Session variables are: –Stored in the Web server's memory –Lost when the Web server is restarted –Used for single site visit Session variables are not stored physically in the server’s or in the database. Instead they are stored in the servers RAM In order to use Session variables, you will need to: 1.Check the ColdFusion Administrator for Session settings 2.Enable Session variables within your Application.cfm file 3.Set Session variables in your ColdFusion pages

36 ColdFusion Administrator Settings Session variables must be enabled before use. Check the following settings in the ColdFusion Administrator to: 1.Make sure that Session variables have not been disabled 2.Set/reset the Session variables default and maximum timeout settings

37 ColdFusion Administrator Settings11-22 Found in the ColdFusion Administrator in the Server Settings section under Memory Variables

38 Enabling Session Variables Enable session variables by using tag. This tag is always included in Application.cfm file. Enable session variables in the Application.cfm file: Enables session variables and sets expiration to 1 hour after last browser activity for each session The maximum timeout default in the ColdFusion Administrator is 20 minutes. Change this value in order for the above tag to allow timeout at 1 hour.

39 After you have enabled session variables using, you can start using them in your code. You can set and use session variables by simply using the Session prefix in front of a variable’s name.

40 1.The first time a browser requests a page from ColdFusion, it will encounter the tag. This is always placed in an Application.cfm file. 2.ColdFusion will generate a unique identifier for the browser. The unique ID is made up of two values: CFID and CFTOKEN. 3.Two cookies are created and sent to the browser: CFID and CFTOKEN. 4.These two values are also stored in the Web server’s memory within the application. This is the link between the Web server and the browser session.

41 Creating Session Variables Session variables are stored in server memory with the matching CFID and CFTOKEN values Each session will have a separate set of variables Once the association between the browser and the session is made, session variables can be created using the tag The Session. prefix is required

42 Creating Session Variables Session variables are stored in server memory with the matching CFID and CFTOKEN values Each session will have a separate set of variables Once the association between the browser and the session is made, session variables can be created using the tag The Session. prefix is required

43 Securing your Applications This line must be wrapped within whatever code validates a users password This line must be put on whatever pages you need to protect Sorry, you don’t have a permission to look at that

44 <!--- Filename: Application.cfm Created by: Nate Weiss (NMW) Please Note: Executes for every page request ---> <CFAPPLICATION NAME="OrangeWhipSite" SESSIONMANAGEMENT="Yes"> All pages in your application have now been locked down and will never appear until you create code that sets the session.auth.isloggedin value

45 Loginform.cfm <!--- Filename: LoginForm.cfm Created by: Nate Weiss (NMW) Purpose: Presented whenever a user has not logged in yet Please Note: Included by Application.cfm ---> Please Log In Read last paragraph of page 473 (cgi script) Please Log In Username: <CFINPUT TYPE="Text" NAME="UserLogin" SIZE="20" VALUE="" MAXLENGTH="100" REQUIRED="Yes" MESSAGE="Please type your Username first."> Password: <CFINPUT TYPE="Password" NAME="UserPassword" SIZE="12" VALUE="" MAXLENGTH="100" REQUIRED="Yes" MESSAGE="Please type your Password first.">

46 Logincheck.cfm <!--- Filename: LoginCheck.cfm Created by: Nate Weiss (NMW) Purpose: Validates a user's password entries Please Note: Included by LoginForm.cfm ---> SELECT ContactID, FirstName FROM Contacts WHERE UserLogin = '#Form.UserLogin#' AND UserPassword = '#Form.UserPassword#'


Download ppt "Week 7 IBS 685. Displaying an Image using CFOUTPUT 1.Save images in a folder under wwwroot directory 2.Create a database column and name it e.g. imagefilename."

Similar presentations


Ads by Google