Jump to content

Dakkadakka

Members
  • Posts

    33
  • Joined

  • Last visited

Everything posted by Dakkadakka

  1. That's wierd. Maybe it's wrong in the tutorial. Changing SessionInfo to sessions when using the sessionData and setSessionData lines removed the error in the error long. Still, it echos back a blank line: echo "Your name is ".$session->sessionData['first_name']." ".$session->sessionData['last_name']."<br>(and the peronalized Level is ".$session->sessionData['price_level'].")"; It turns out another problem problem might be in sessionCheck: public function sessionCheck(){$dbuser = "@#)(*%&@#)*(%";$dbpass = "&&********";$host = "localhost";$dbname = "*********"; // database connectionmysql_connect("localhost", $dbuser, $dbpass) or die(mysql_error());mysql_select_db($dbname) or die("Unable to select database");//Set the hash which we get from the class. $hash = mysql_real_escape_string( $this->sessionHash );//The IP address is grabbed directly from the server. $ip = $_SERVER['REMOTE_ADDR'];//The Expiration time is recalculated. $expiryLimit = time() - $this->expireTime; //Find the matching session in the database. $check = mysql_query( "SELECT * FROM sessions WHERE sessionHash = '{$hash}' AND sessionIP = '{$ip}'" ); if( mysql_num_rows( $check ) > 0 ) { # Session exists and is valid. We update the session.//First, we find that session all over again. $sessionInfo = mysql_fetch_array( $check );//We decode it.$this->sessionData = unserialize( $sessionInfo['sessionData'] );//We add an extra fifteen minutes.$expire = time() + $this->expireTime;//We update this session in the database.$update = mysql_query( "UPDATE sessions SET sessionExpire = '{$expire}' WHERE sessionHash = '{$hash}'" ); return true; } else { # Session does not exist or is invalid. return false; }} Serialization is something I've never worked with before, but the internet says that serialization changes an object to "stdClass" if the class cannot be found. But this function is IN the class itself. I can't make the class include itself: that causes a memory error. All my files include the class file at the top, how do I make sure it's acknowledging the class? Also, the session class has no insertion of any kind. What is the point of making the mysql db if it can't create new sessions? When does this need to happen? In the class or during login?
  2. I don't know. SessionInfo looks like this according to the tutorial. Thank you for the details on evaluating sessions. <?php include "class.session.php"; $sessions = new sessionClass; $sessions->_sessionStart(); $sessionInfo = $sessions->sessionCheck(); if( $sessionInfo = false ){ # This session is invalid. Tell the user.}else{ # Session is valid, can use the data.} ?>
  3. I'm trying a quick and dirty login without a registration that checks for an existing customer in the database, and I have wierd errors. The end of my login, after successfully finding a user looks like this.: while($row=mysql_fetch_array($result)){//Grab the database pieces the customer will need throughout the page.$customer_id = $row['customer_id'];$first_name = $row['first_name'];$last_name = $row['last_name'];$first_name = $row['price_level'];} //Give the user a session.$sessions = new sessionsClass;$sessions->_sessionStart(); $sessionInfo = $sessions->sessionCheck(); if( $sessionInfo = false ){ # This session is invalid. Tell the user.}else{ # Update the name. $sessionInfo->sessionData['customer_id'] = $customer_id; $sessionInfo->sessionData['first_name'] = $first_name; $sessionInfo->sessionData['last_name'] = $last_name; $sessionInfo->sessionData['price_level'] = $price_level; $sessionInfo->setSessionData();//this is line 71 # Session is valid, can use the data. echo "Your name is ".$sessionInfo->sessionData['first_name']." ".$sessionInfo->sessionData['last_name']."<br>";} And the error log on my hosting service says this:PHP Fatal error: Call to undefined method stdClass::setSessionData() in /home4/danielga/public_html/templogin/logincheck.php on line 71 setSessionData clearly exists. It looks like this, straight out of the tutorial page, modified so it uses my database: public function setSessionData(){$dbuser = "(*@#&^$%(&*@#^%";$dbpass = "@#*$%&^@#(&*%^@#";$host = "@#&*(%^)(@^%t";$dbname = "@#I%@#(%*^#@)"; // database connection mysql_connect("localhost", $dbuser, $dbpass) or die(mysql_error());mysql_select_db($dbname) or die("Unable to select database");//Encrypt the data. $serialiseData = serialize( $this->sessionData ); //Update the session data. mysql_query( "UPDATE sessions SET sessionData = '{$serialiseData}' WHERE sessionHash = '{$this->sessionHash}'" ); } What could be the problem here?Also, as I implement this I still wonder, if I'm making a shopping cart, what needs to be included page to page to page so that generic users can still see the typical things I've set up whereas logged in users use the personalized session? That's my ultimate goal because the shopping cart I'm working on at my internship has a major goal of giving logged in customers personalized prices, hence the "$sessionInfo->sessionData['price_level'] = $price_level;" line.
  4. Another this missing from this article is the way to check a username and password. I will be checking for an email and password actually, and while I know how to do that it says there is a way to make the session class check it. If I make a registration page (which I have) and I am filling a table called "online_customers" with registration entries, what needs to happen in the sessions table?
  5. That's amazing. My coworker and I were like "oh, TEXT is some string", when in fact it has very useful properties that make it different from say, a VARCHAR. That's fantastic. Thanks!
  6. I'm working on a shopping cart that calls for a secure login and certain data fields being kept as users move page to page. This is very important because the beta version of the site gives discounts on the individual user level, and the first version of this site will be exclusively for customers who have a history with my company. It won't be for everybody until we're good and ready to expand. It's just for the customers who want to be able to order things from their computer for now. When I did my senior design page, it had a very superficial login with a user name and password, and if you knew the URL, you could just type it in. Now I'm trying to make a secure session. So I'm following along in this tutorial to make an entire secure session PHP class. http://tutorial-resource.com/2011/10/a-secure-session-management-class-in-php/ I followed along in the tutorial, creating every piece line by line so I could understand it as best I could, but there are a few things I don't understand. First, I want to add certain lines so they stay page to page, such as "first name", "last name", and a customer id number. Then there's the line near the end of the tutorial which really confuses me: # Update the name. $sessionInfo->sessionData['fullname'] = "My New name"; $sessionInfo->setSessionData(); If SessionData is a TEXT data field in the MySQL database, and we are setting sessionData['fullname'] as some string, how is that accessed? May I arbitrarily make more fields such as sessionData['first_name'], sessionData['last_name'] and sessionData['customer_id']? How would that work if the sessionData row in the database is one row of text? Also, I see nothing in the class about what needs to happen when a user clicks Logout. Lets say I need to make my own Logout button, which is fine. How would properly terminating a session work?
  7. Left and right made no change, but trying a FULL OUTER JOIN or FULL JOIN yield SQL errors. What would the proper syntax for this be? SELECT products.full_name, SUM( customer_categories.qty ) AS qtyFROM productsFULL OUTER JOIN customer_categories ON products.full_name = customer_categories.nameWHERE products.sub_level =0AND products.purchase_cost =0AND customer_categories.depth =2GROUP BY products.full_nameORDER BY qty DESC
  8. I'm at an internship working on a shopping cart, and I want to create a navigation bar that rearranges the product categories based on their popularity. This requires two tables. The first table is customer_categories, which shows all customer purchases made in the past three months. Because it only goes up to three months, it presents the problem that items with zero purchases do not show up, which leads me to the next table: The second table is called products, and it has the entire inventory. I need this to find out exactly what are ALL the major categories. First, this query gives me every major category: $categorylist = "SELECT full_nameFROM productsWHERE sub_level =0AND (purchase_cost =0OR purchase_cost IS NULL)"; This yields every category (note that the undefined line at the bottom is items that still need to be given categories, don't worry about that one):1 - CLEARANCE ACCOUNTB - CHEMICAL & JANITORIALC - ODOR CONTROLD - SKIN CARE & PERSONAL HYGIEE - PAPER & DISPENSERF - MOPS, BROOMS & BRUSHESG - FLOOR & CARPET CAREH - FACILITY MAINTENANCE & SAFEI - STORAGE & MATERIAL HANDLINGJ - Waste ReceptaclesK - BAGS & CAN LINERSL - FOOD & BEVERAGE SERVICEM - REGULAR & SMALL APPLN - FOODSERVICE DISPOSABLEP - ROOM AMENITIES & ACCESSOQ - LINEN & ACCESSORIESUNDEF Item To get item popularity I use the following query on the other table (and the undefined items are most popular, lol)$query = "SELECT SUM(qty), name FROM customer_categories where depth = 2 GROUP BY name ORDER BY SUM(qty) DESC"; UNDEF ItemE - PAPER & DISPENSERK - BAGS & CAN LINERSB - CHEMICAL & JANITORIALQ - LINEN & ACCESSORIESL - FOOD & BEVERAGE SERVICEN - FOODSERVICE DISPOSABLEH - FACILITY MAINTENANCE & SAFEP - ROOM AMENITIES & ACCESSOF - MOPS, BROOMS & BRUSHESC - ODOR CONTROLD - SKIN CARE & PERSONAL HYGIEG - FLOOR & CARPET CAREWhat kind of join statement would let me get the bottom result, but with the categories with zero purchases put on the bottom? I tried this but it didn't work. It still leaves out the zero (null) categories.SELECT products.full_name, SUM( customer_categories.qty ) AS qtyFROM productsLEFT OUTER JOIN customer_categories ON products.full_name = customer_categories.nameWHERE products.sub_level =0AND products.purchase_cost =0AND customer_categories.depth =2GROUP BY products.full_nameORDER BY qty DESC UNDEF Item 381480E - PAPER & DISPENSER 1624K - BAGS & CAN LINERS 829Q - LINEN & ACCESSORIES 598L - FOOD & BEVERAGE SERVICE 228N - FOODSERVICE DISPOSABLE 220H - FACILITY MAINTENANCE & SAFE 158P - ROOM AMENITIES & ACCESSO 70F - MOPS, BROOMS & BRUSHES 43C - ODOR CONTROL 36D - SKIN CARE & PERSONAL HYGIE 19G - FLOOR & CARPET CARE 2
×
×
  • Create New...