Jump to content

[SOLVED] Sessions and Stuff


soccadude

Recommended Posts

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]

Link to comment
Share on other sites

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'];
    //}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.