This is a discussion on Alternative to Cookies within the PHP Language forums, part of the PHP Programming Forums category; I am coming from (an elementary-level) javascript background. I set cookiesin select pages to see where the users are ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am coming from (an elementary-level) javascript background. I set
cookiesin select pages to see where the users are coming from and where they are going. It works quite nicely except that I'd like to write the data into a file and look at it. I have reached a dead end with JS it seems. I have thought about implementing the same with PHP (I know nothing about it but I'm willing to learn) but the disadvantage of PHP as I understand is that the pages need to be refreshed in between setting and reading the cookies. It seems to me that since my interest is only in the value of the cookie, I could do away with this method entirely and simply set a variable that is updated upon visiting a page. My questions are: Can I set a global variable whose value is updated as each page is loaded? Can I check the value of the variable and dump this into a file or database? Are there other, better means of doing the same? Where can I find more info (I did check into php.net which I found overwhelming)? TIA. KK |
|
|||
|
Hello,
I hope you are doing well in you stately pleasure dome. Below are a couple very simple examples. Apologies if they are too simple. Yes, you can pass standard local variables from form to form via GET(url) or Post(form) as well as with Session / Global variables. With session variables, the session has to be started first, perhaps as follows: your first page might be: <?php session_start(); $name=$_POST['name']; //now that the session is started, you can load a session variable with what you want to pass, //maybe a posted variable as in this example $HTTP_SESSION_VARS['the_names']=$name; ?> when you arrive at another page as below, you can get the session value or append to the value like this: <?php session_start(); $another_name=$_POST['another_name']; //now that the session is started, you can load the prior session variable from prior page $the_names_are=$HTTP_SESSION_VARS['the_names']; //concatenate the next name $the_names_are=$the_names_are."<br>".$another_name ; //then reload the session variable with the revised list $HTTP_SESSION_VARS['the_names']=$the_names_are; ?> The session variable can be a standard array as well, loaded in the same manner as other PHP arrays: $HTTP_SESSION_VARS['the_names']=array(); $HTTP_SESSION_VARS['the_names'][0]='Joe Smith'; $HTTP_SESSION_VARS['the_names'][1]='Steve Jones'; Obviously with arrays, you can organize your data more efficiently. When you are done, you can pass the contents of the session variable to your database by building custom queries with your variables. Note: Users might have privacy settings set in such a way as to not allow the passing of session variables. If you determine this ahead of time, you can pass variables via URL or, if Javascript is enabled on the client, you can auto-submit a form with hidden post variables to pass to the next page. You can also put them in a database and track them that way. A simple but fairly thorough book to get review: PHP and MySQL Web Development by Luke/Laura Welling An incredible book to get review is: PHP Cookbook by David Sklar & Adam Trachtenberg Scott kublai khan wrote: > I am coming from (an elementary-level) javascript background. I set > cookiesin select pages to see where the users are coming from and where > they are going. It works quite nicely except that I'd like to write the > data into a file and look at it. I have reached a dead end with JS it > seems. I have thought about implementing the same with PHP (I know > nothing about it but I'm willing to learn) but the disadvantage of PHP > as I understand is that the pages need to be refreshed in between > setting and reading the cookies. It seems to me that since my interest > is only in the value of the cookie, I could do away with this method > entirely and simply set a variable that is updated upon visiting a > page. My questions are: > Can I set a global variable whose value is updated as each page is > loaded? Can I check the value of the variable and dump this into a file > or database? Are there other, better means of doing the same? Where can > I find more info (I did check into php.net which I found overwhelming)? > TIA. > > KK |
|
|||
|
Hi Thanks. No pleasure dome here when I'm out here trying to conquer
PHP :) I picked up PHP cookbook on your suggestion. It seems that cookies will work fine for what I want to do. Sorry I didn't explain myself well. BUT, analogous to what you have suggested, I wonder if setting a session_id would be a better idea since the variable can be passed to other pages & subsequently updated. Moreover, it also gets around the issues with client permissions. Is this a viable idea? TIA |