soccadude Posted August 21, 2009 Share Posted August 21, 2009 My website has pages that require you to view one before you are able to view the next. So, I'm trying to create a code that is User Specific, that when they view a page. Their entry for curentpage in my table updates. I don't want it to replace the previous one if they want to go back and view previous pages. I want to keep track of how far they have gone though. So far, this is what I have. I am new to php, so please excuse me if this is extremely simple. update.php <?php session_start(); include ("config.php"); // current page will be called from each page, name of the page: toys, cars, soda, etc... $user=$_SESSION['user']; //username or id $query="update `users` set `lastpage`='$currentpage' where `user`='$user'"; $result=@mysql_query($query) or die(mysql_error()); ?> then on each .htm page I am going to do an include, to call up that previous code above. <? php $currentpage="toys"; include ("update.php"); ?> I want it to update though when the person visits the page. I attempted to do an onLoad command, however this didn't work for me. Any suggestions or advice would be greatly appreciated. [my verification question was invalid "what is the square root of 9?", I put +/-3 it was looking for just 3] Quote Link to comment https://forums.phpfreaks.com/topic/171310-solved-sessions-and-stuff/ Share on other sites More sharing options...
Daniel0 Posted August 21, 2009 Share Posted August 21, 2009 [my verification question was invalid "what is the square root of 9?", I put +/-3 it was looking for just 3] Ha... good catch. Fixed now. Quote Link to comment https://forums.phpfreaks.com/topic/171310-solved-sessions-and-stuff/#findComment-903440 Share on other sites More sharing options...
ignace Posted August 21, 2009 Share Posted August 21, 2009 Use sessions. session_start(); if (!isset($_SESSION['urls_visited'])) {// 'urls_visited' doesn't exist yet meaning this is the first page the user has visited. $_SESSION['urls_visited'] = array(); $_SESSION['urls_visited'][] = $_SERVER['PHP_SELF'];//register the current page as visited. } else {// 'urls_visited' exists meaning he has visited atleast one page. //if (!in_array($_SERVER['PHP_SELF'], $_SESSION['urls_visited'])) {//if you want unique pages visited then uncomment this however you will lose the order in which he visited them. $_SESSION['urls_visited'][] = $_SERVER['PHP_SELF']; //} } Quote Link to comment https://forums.phpfreaks.com/topic/171310-solved-sessions-and-stuff/#findComment-903525 Share on other sites More sharing options...
soccadude Posted August 21, 2009 Author Share Posted August 21, 2009 Use sessions. Well, that's kind of obvious considering the title of this thread. But, I appreciate your efforts. However I need the pages to be in order and for the proceeding one not to replace the previous when you revisit an old page. Quote Link to comment https://forums.phpfreaks.com/topic/171310-solved-sessions-and-stuff/#findComment-903692 Share on other sites More sharing options...
ignace Posted August 22, 2009 Share Posted August 22, 2009 Use sessions. Well, that's kind of obvious considering the title of this thread. But, I appreciate your efforts. However I need the pages to be in order and for the proceeding one not to replace the previous when you revisit an old page. You mean like a history? That is what my current code is designed for it will log each and every page visit (even refreshes altough you can exclude these if you get the last page visited and compare that to the current page). Use $array[$length - 2] to get the previous url visited as $array[$length - 1] will be the current page $array[0] is the page of entry. Quote Link to comment https://forums.phpfreaks.com/topic/171310-solved-sessions-and-stuff/#findComment-903889 Share on other sites More sharing options...
soccadude Posted August 23, 2009 Author Share Posted August 23, 2009 This is along the lines of what I want I suppose, it still doesn't seem like it will quite do what I'm hoping to accomplish. I was thinking about using the mod_rewrite module to make my pages look like html, while using php. I'm not sure, I'm going to just give up on this one and mark it as solved. Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/171310-solved-sessions-and-stuff/#findComment-904241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.