[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Sessions using Dreamweaver

Posted on 2008-06-10
7
Medium Priority
?
831 Views
Last Modified: 2013-12-13
I am developing a real estate search engine using primarily Dreamweaver for the search, results, and details page functionality. The site is working very slick and its time to add an "Add to Favorites / View Favorites" feature. When a consumer searches for properties, we want to give them the ability to add property detail pages to their list of favorites. When they leave the site and come back, we also would like them to be able to log in and view the list of favorites. I know this involves sessions. Where do I begin?
0
Comment
Question by:BMXPRO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 31

Expert Comment

by:Frosty555
ID: 21755066
Provided that your PHP is setup to support sessions, it's pretty easy to use them.

Begin any page that will use sessions with the statement:
   session_start();

Now, you can access session variables via the $_SESSION[] array. Session variables will maintain their value inbetween page views for each user. Each user has their own unique session, and it expires when the user leaves the webpage or closes their browser.

For example, if on page1.php, you did:
   $_SESSION["test"] = "hello!";

And in page2.php, you did:
   echo $_SESSION["test"];

The user would view page 2 and see nothing. Then they would visit page 1. When they goes back to page 2, the session var is set and he would see "hello!" on the screen.

You can put an array in the session:
    $_SESSION["favorites"] = array();

and use push new items onto the array using array_push() to add a favorite. Later you can use a foreach{} loop to loop through all items in the array to list the favorites for the user.

Saving the favorites so the user can see them *after* they leave the page, and allow them to log back in later, will require a database (e.g. mysql), where you can store the favorites and user logins, and in that case sessions would only be used to keep track of the login name of the user visiting the page. The favorites would be stored in the database and accessed via a SQL query every time you need it. This also means it would be mandatory for the user to register a username and login before they can use the favorites feature.
0
 
LVL 31

Accepted Solution

by:
Frosty555 earned 1500 total points
ID: 21755174
So... to do user logins and store favorites that way, you need databases as well as sessions, and things get a fair bit more complex. You'll need to identify what kind of database technology your webhost provides for you.

Various help topics from php.net to help you further:


Tutorial on sessions by W3Schools:
http://www.w3schools.com/PHP/php_sessions.asp

Tutorial on arrays by W3Schools:
http://www.w3schools.com/PHP/php_arrays.asp

Tutorial on using MySQL with PHP, again by W3Schools
http://www.w3schools.com/PHP/php_mysql_intro.asp


Session function reference:
http://ca.php.net/manual/en/ref.session.php

PHP Arrays reference:
http://ca.php.net/manual/en/language.types.array.php

Array_Push() function:
http://ca.php.net/manual/en/function.array-push.php

Foreach construct - for loop for looping through an array in PHP:
http://ca.php.net/manual/en/control-structures.foreach.php

0
 

Author Comment

by:BMXPRO
ID: 21755432
Frosty555,

We're using mySQL & PHP. Thank you so much for the tips. I have to leave the office now for a fews hours...will try some things upon return.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BMXPRO
ID: 21762838
Frosty,
Do you have (or know of) any example code that accomplishes what I'm trying to do?
0
 
LVL 31

Expert Comment

by:Frosty555
ID: 21769381
There's quite a bit of sample code regarding how to use each function on PHP's website in the links I provided above. You will want to do some reading on the subject before you dive in. Those W3Schools links are excellent for getting started in the learning department.

But here's a simple script on how to setup logins using MySQL and PHP:
http://www.phpeasystep.com/workshopview.php?id=6

You can see it stores the logged in user's credentials in the session variables "myusername" and "mypassword".

Later you would need to create another MySQL table to hold the favourites, and use the myusername session var to select that one user's favourites list and display it on your page.
0
 

Author Comment

by:BMXPRO
ID: 21781767
Frosty555,
My deadline is quickly approaching. I'm trying to learn this in a very short time. Would you be available to help code the basic functionality of this?
0
 

Author Closing Comment

by:BMXPRO
ID: 31465930
Frosty555 helped me along with his tutorial links.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question