PHP - Track Session Requests?
How can I track session requests, so I can, after a certain number of requests (let's say ten because it's physcologically pleasing), have the id regenerated?
Similar TutorialsIt's been a while since I've needed to whip anything substantial up from scratch, so my scripting is a little (lot) fast and loose (weird/inefficient) here. I'm trying to mock up a script that's essentially a quiz/survey. There are a handful of topics, each with a few screens of yes/no questions. At the end, it returns a list of recommendations based on the answers gathered. The script is posting back to itself. Using print_r ($_SESSION), it seems like all of the post values for the first screen of questions are being assigned to the session array as expected. When the second screen of questions is answered, their values are assigned as well, but the values for the first set go away completely. This continues through subsequent screens, with the values from the previous screen present and all others before missing. I'd really appreciate a look at my code to see if you tell me the cause or error(s). Thanks! <?php session_start; include('_config.php'); // database connect $dbc = mysqli_connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname); // set to section 1, page 1 if no values are in _POST array if (($_SERVER['REQUEST_METHOD'] == 'GET') || (!isset($_POST['section']))) { $section = 1; $page = 1; } else { // something was posted, so...set those values in session variable foreach($_POST as $key => $data) { $_SESSION[$key] = $data; } // debug: display contents of the session array print_r ($_SESSION); // which section and page? $section = (int) $_POST['section']; $page = (int) $_POST['next']; } // check if last topic $query = "SELECT * FROM hw_topics"; $data = mysqli_query($dbc, $query); if ($section == mysqli_num_rows($data)) { $last_section = true; } else { $last_section = false; } // get current topic name and info $query = "SELECT topic, display_name, pages_in_topic FROM hw_topics WHERE topic_id = '$section'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { $row = mysqli_fetch_array($data); $topic_display_name = $row['display_name']; $pages_in_topic = $row['pages_in_topic']; } // test if last page in topic $topic_pages = $row['pages_in_topic']; if ($page == $topic_pages) { $last_page_in_section = true; } else { $last_page_in_section = false; } // set form action (set to this script or to recommendations when last section is complete if (($last_section == true) && ($last_page_in_section == true)) { $form_action = $CFG->reccomend; } else { $form_action = $_SERVER['PHP_SELF']; } // get current page headline $query = "SELECT page_headline FROM hw_pages WHERE topic_id = '$section' AND page_number = '$page'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The headline row was found so display the headline $row = mysqli_fetch_array($data); $page_headline = '<h2>' . $row['page_headline'] . '</h2>'; } // Grab the question data from the database to generate the list and form fields $query = "SELECT question_id, question_number, question_text FROM hw_questions WHERE topic_id = '$section' AND page_id = '$page' ORDER BY question_number"; $data = mysqli_query($dbc, $query); $questions = array(); while ($row = mysqli_fetch_array($data)) { array_push($questions, $row); } include($CFG->includesdir.'/header.php'); ?> <div id="head"> <h1>Assessment<?php if (isset($topic_display_name)) { echo ': <em>' . $topic_display_name . '</em>'; } ?></h1> <p class="paging">Page <?php echo $page; ?> of <?php echo $pages_in_topic; ?></p> </div><!-- #head --> <div id="content"> <p class="instr">Please complete this survey. We'll generate a list of recommendations and resources for your organization.</p> <div id="questions"> <?php echo $page_headline; ?> <form method="post" action="<?php echo $form_action; ?>"> <table border="0" cellpadding="0" cellspacing="0"> <thead> <tr> <td></td> <td class="qtext"></td> <td class="qanswer">yes</td> <td class="qanswer">no</td> <td class="pad"></td> </tr> </thead> <?php if ($questions) { // display question rows foreach ($questions as $question) { echo '<tr>'; echo '<td class="qnumber">' . $question['question_number'] . '.</td>'; echo '<td class="qtext"><p>...' . $question['question_text'] . '</p></td>'; echo '<td class="qanswer"><div class="radio" id="box-yes"><input type="radio" value="yes" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio" /></div></td>'; echo '<td class="qanswer"><div class="radio" id="box-no"><input type="radio" value="no" name="qid_' . $question['question_id'] . '" id="qid_' . $question['question_id'] . '" class="radio"'; $field_name = 'qid_' . $question['question_id']; if (isset($_SESSION[$field_name])) { echo ' checked="checked"'; } echo ' /></div></td>'; echo '<td class="pad"></td>'; echo '</tr>'; } } else { echo '<tr>'; echo '<td colspan="3" class="qtext"><p>No questions found in the database for this page.</p></td>'; echo '<td class="pad"></td>'; echo '</tr>'; } ?> </table> <ul id="controls"> <?php if ($last_page_in_section == true) { $section++; $page = 1; } else { $page++; } echo '<input type="hidden" value="' . $section . '" name="section" />'; echo '<input type="hidden" value="' . ($page) . '" name="next" />'; if (($last_section == true) && ($last_page_in_section == true)) { echo '<li><input type="submit" value="Submit Answers and Get Recommendations" name="submit" id="submit" /></li>'; } else { echo '<li><input type="submit" value="Next Page" name="submit" id="next" /></li>'; } ?> </ul><!-- #controls --> </form> </div><!-- #questions --> <?php mysqli_close($dbc); include($CFG->includesdir.'/footer.php'); ?> I was just wondering if when I write a new function that uses AJAX should I use the same http request for my whole website or should I make seperate ones for each function? Also if you use the same one do you need to do anything to it once it has been used to set the ready status back to 0? Thanks Hi, I am trying to make a web interface for a robot, I have written php to send/recieve values via a serial port to my robot. They work. I am now tring to develop my web interface. I'm using java to generate http requests client side in the form of; Code: [Select] /request?command=Forward¶m1=254 I was wondering how I can parse the command and param1 in php sereverside? Or is there a better alternative? Hello! I'm trying to understand exactly how http requests relate to a php script. 1) What would be considered a large amount? 2) How can I see how many I have for a given page? Thank you, Eric I think it's fsockopen that enables you to do web requests right?? I was wondering if you could also make it use a proxy instead of your website's IP. Would that be possible? Hello there everyone. I'll try to explain as thorough as I can so please bare with me a bit. One you want to surf the web through a proxy in firefox, you go to tools > options > network > settings and enter proxy details which for example are like this. 173.123.123.4 and port 8080. I want to do pretty much the same thing with php for my visitors. I have www.site1.com which will have all my scripts and stuff. I want it to somehow redirect or load to www.site2.com USING A PROXY so that when the visitor reach site2, it's as if they have edited their firefox settings to view site2 using a proxy. That way visitors will always be anonymous on www.site2.com. While searching, I found this: http://stackoverflow.com/questions/3889715/php-requests-through-proxy Which seems simple enough but does not work unfortunately. Not that I'm even sure that it's indeed what I want to do but it seems like it...lol. Thanks a lot for any help provided. I have an object which is very expensive to create, and is fairly large but by no means enormous. The object has two tasks: Display to the user what can be changed in a database. Make some or all of those changes based on user input.Instead of creating it first to perform the first task, I would like to serialize it and store it somewhere and then restore it to perform the second task to reduce user wait time. Communication of both tasks is as follows where the web client first makes a XMLHttpRequest and then cURL is used for the remaining: Web Client -> Web Server -> REST API Server -> Time Historian Application (and then back in the same order) In addition, both of these tasks take significantly longer than 30 seconds resulting in cURL error 28. I certainly can investigate to determine which of the requests are causing this error, however, feel that the solution to persisting the object might solve this issue as well. I am thinking of making the REST API server responsible for temporarily storing the object, and am considering the following: Web client makes XMLHttpRequest to web server and passes session cookie. Web server makes cURL request to REST API server and passes that same cookie (maybe a bad idea?). REST API server initiates the time historian application, spawns some new process, and replies to the web server maybe with some expected wait time duration, and web server in turn responds to web client. Spanned process when object is complete serializes the object's content and saves it as JSON using the session cookie as the filename. Web client periodically makes requests to web server which in turn make requests to REST API server and when the JSON file is available, recreates the object, executes the applicable method, and replies with the applicable content. Web client sends user data to the web server and in turn to the REST server to initiate the second task. Web client similarly periodically makes requests to web server which in turn make requests to REST API server to check if complete and if so the JSON object file is deleted. If request has not been fulfilled within 24 hours or so, JSON object file is deleted.I would appreciate any general feedback or recommendations how best to accomplish this, and whether using some 3rd party framework such as Gearman, ReactPHP, redis, etc might simplify matters. Thank you I have script on my web hosts server built into pages that will be offered to the public, eg: index.php will have some script amongst the html, this script calls other webpages on the net eg: wiki.org Now my question is, when that script runs when somebody accesses that page, will the website eg: wiki.org record the users browser info and ip who called my index page or will it record the webhosts server details as the one making the requests? I created an app for my website, set action (read) and object (article), and placed the objects code (META tags in the head) at the article page on my website. Now, I want to know how to send a cUrl request whenever a user reads an article on my website, so it'll feature on his wall. When I press the "get code" link near the action, that's what I get: Code: [Select] curl -F 'access_token=***' \ -F 'article=http://example.com' \ 'https://graph.facebook.com/me/yellowheart:read' (There's an actual access token of course). Now, how do I make it happen? Daniel Purpose: Building a search function for a site, that's supposed to be fast, give results as a user types. Queries would be something like: "brand1 brand2 brand3" . My idea is , instead of querying the database on each ajax request. A keyed array is created once. Like: ['brand1' => id , 'brand2 => id2 ]. This array is stored in memory. The next time a query is sent, the array which is instantly available in memory, and can be simply queried $storedArray['brand1']to fetch any existing ids instantly. The array size would be about 750 Kb. 60000 rows. I don't have much experience with caching , so looking for advise whether what I am trying to do even makes any sense or necessary. I know there are solutions like memcache. But not sure if my tiny project requires them. Also does opcache help here ? Would serializing the array be too slow ? Please ask if any questions. Thanks Hi all, Something i forget to ask all the time, but now i don't. While reading again about image sprites, it tells that it's nice because it decreases the amount of http requests. Now I thought what about all those requires and includes of php aren't they doing the same thing? Not to mention OOP which would not exist without the 2(4). Does anyone know if this indeed increases the amount of http requests. And if so, if there is a certain good practise to lower the amount, by just combining functions in 1 file. I would love to hear from some guru's Hi,
i am a student for a school.
we have in each class a book that lists the shool year. Teachers use it to make notes in it and mark people that are not present.
i want to bring that whole process online making a website out of it.
Teachers can log in and see the yearbook. Days view, Week view, Month view. Mark people that have been missing on a specific day. List all the people that have been missing during a school week.
How would i present the Calender? Tables?
I have the some knowledge in mysql, php and joomla.
How would i go about getting startet? Do i need to have a Framework?
All ideas would be greatly appreciated.
Thank you
I have a site where people vote, currently if two computers that are on the same network vote, my site will see them as one computer because I only track people by IP address. What would be a good way to track 2+ computers with the same IP address? Hello! I want to build a script to basically keep track of the number of hosting accounts that are currently on each server. I have roughly 30 servers (root access, WHM, cPanel) that I would like to be able to track all of from a single page. Could someone help/point me in the right direction/offer any input? thanks! much appreciated! I've searched the forum, and haven't yet found what I need. I have a long list of PDF files: http://www.iampeth.com/vintage_magazines.php How can I track the number of downloads for each file? Hi all, I followed a tutorial to get the base of a php calendar done, then added some custom Javascript in order to be able to change the color of the cells. The calendar can be seen he http://www.education-world.co.uk/Education%20World%20Site/calendar.php The problem is now, that I need to integrate a SQL database to keep track of what was set for certain dates. I'm not sure of how to even begin this, all i need to do is keep track of if the candidate is available, not available or working for a specific day. The calendar is submitted to an email but this means when they return at a later date (availability may change) their previously set availability will have been wiped! I can provide code if needed. Can anyone help me out here, really struggling with this! Many thanks, Greens85 So i have a bunch of random videos playig one after the other what i want is to track if the user viewed the videos by inserting a view lets say in to the database, so if they view the first video the database will increment by 1 then after the page refreshes and the next video loads it will increment again, the only part i dont know what im doing is how would i know if my user viewed the video, any help please thank you? What is the best way to keep track of a User's (real-time) online status? Right now I have a Log In script and I set the status in the User's Session, and then "pass" that status from page to page with session_start();. However, the problems with this approach include... 1.) A User is idle for hours or days and thus not really online 2.) A User leaves my site and thus is not really online (Or does closing the window change that?) I want a fairly accurate and real-time reading of whether or not a User is actively using my site so I can set their "Online Status" icon as green (online) or yellow (in active) or grey (offline). Any idea how to accomplish that so I have monitoring like you'd see on an Instant Messenger App? Thanks, Debbie Hi everybody,
I want to cloak my affiliate links or mask it so it looks like a pretty url. Also if possible, I want to track the clicked link with Google Analytics so I think I need a page where I can log the click.
I found lots of information but not for the situation I have. I get my links from my database like this:
echo '<a href="'.$info['url'].'">the link</a>';How can I accomplish this? So I need a url like www.mydomain.com/click and when a user click on the link the get a new page with a tracking code and a redirect script to the right url. Thanks so much for the help! Kind regards, Mark Hello,
I have been looking for a way to track the play stats on audio mp3's in the admin of my custom post-type. Whatever I google seems to come up with nothing. I not very versed in audio player code - could someone please point me in the right direction.
Again:
I have a custom post-type which uses the wordpress default audio.
I would like to get the number of plays for each audio file and display that in the admin column for my custom post-type
Thanks,
Drew
|