PHP - Total Time Users Spent On Page?
I have a Yahtzee system
Code: [Select] session_start(); $_SESSION['Yahtzee']['totaltime'] =time(); echo $_SESSION['Yahtzee']['totaltime']; Now, Long STORY Short when somone finishes playing the Yahtzee, I update there username with the score they had, and I want to update how long they have been playing, and it will be for "Total Time Playing globally" no matter how many games. If I do this session and echo it out, it echo's out the time, but I need it to echo out seconds instead so I can just add that to my totaltime field in my database each time they finished a game. Similar TutorialsHiya! , I'm currently working on a script that will allow me to track the total users on my website, and how many of these user are logged in members, or guests. I need to be able to find out the total users, total logged in, and total guests within the last 15 minutes, and the total users, total logged in, and total guests for today. Ideally, I would like to user only one table for this, and would also like to group together records in the database that have the same users_id and ip_address, as there's not much point in storing this more than once. I currently have a table that contains the following fields. sid - Stores the users session ID. user_id - Stores the user id of a logged in user. 0 is stored if the user is a guest. ip_address - Stores the IP address of the user. last_updated - Stores a timestamp of when the user was last active. I look forward to reading your responses Cheers! This code works just fine to display a list of reservations for a given day and sums the guest and table counts just fine for the entire day. Sums all reservations returned.
What I am trying to do or figure out is a way to get totals based on specific time intervals. For example how many guests and tables at 8:00, 9:00, 10:00, etc....
I can see where the sums are calculated, but need help adding a way to add a variable to look at the reservation_time and sum by hour rather than just daily total.
$tablesum ++; $guestsum += $row->reservation_pax; <?php echo $guestsum;?> <?php echo _guest_summary;?>The full code that pulls in the data and then sums it up in total: <!-- Begin reservation table data --> <br/> <table class="global resv-table-small" cellpadding="0" cellspacing="0"> <tbody> <tr> <?php echo "<td class='noprint'> </td>"; echo "<td>Time</td>"; echo "<td>Guests/Type</td>"; echo "<td>Name</td>"; echo "<td>Special Instructions/Notes</td>"; echo "<td class='noprint'>Table</td>"; echo "<td class='noprint'>Status</td>"; echo "<td class='noprint'>Created</td>"; echo "<td class='noprint'>Details/Delete</td>"; echo "</tr>"; // Clear reservation variable $reservations =''; if ($_SESSION['page'] == 1) { $reservations = querySQL('all_reservations'); }else{ $reservations = querySQL('reservations'); } // reset total counters $tablesum = 0; $guestsum = 0; if ($reservations) { //start printing out reservation grid foreach($reservations as $row) { // reservation ID $id = $row->reservation_id; $_SESSION['reservation_guest_name'] = $row->reservation_guest_name; // check if reservation is tautologous $tautologous = querySQL('tautologous'); echo "<tr id='res-".$id."'>"; echo "<td"; // daylight coloring if ($row->reservation_time > $daylight_evening){ echo " class='evening noprint'"; }else if ($row->reservation_time > $daylight_noon){ echo " class='afternoon noprint'"; }else if ($row->reservation_time < $daylight_noon){ echo " class='morning noprint'"; } echo " style='width:10px !important; padding:0px;'> </td>"; echo "<td id='tb_time'"; // reservation after maitre message if ($row->reservation_timestamp > $maitre['maitre_timestamp'] && $maitre['maitre_comment_day']!='') { echo " class='tautologous' title='"._sentence_13."' "; } echo ">"; echo "<strong>".formatTime($row->reservation_time,$general['timeformat'])."</strong></td>"; echo "<td id='tb_pax'><strong class='big'>".$row->reservation_pax."</strong> <span class='noprint'>"; printType($row->reservation_hotelguest_yn); //echo "<img src='images/icons/user-silhouette.png' class='middle'/>"; echo "</span></td><td style='width:10%' id='tb_name'><span class='noprint'>".printTitle($row->reservation_title)."</span><strong> <a id='detlbuttontrigger' href='ajax/guest_detail.php?id=".$id."'"; // color guest name if tautologous if($tautologous>1){echo" class='tautologous tipsy' title='"._tautologous_booking."'";} echo ">".$row->reservation_guest_name."</a></strong>"; // old reservations symbol if( (strtotime($row->reservation_timestamp) + $general['old_days']*86400) <= time() ){ echo "<img src='images/icons/clock-bolt.png' class='help tipsyold middle smicon' title='"._sentence_11."' />"; } // recurring symbol if ($row->repeat_id !=0) { echo " <img src='images/icons/loop-alt.png' alt='"._recurring. "' title='"._recurring."' class='tipsy' border='0' >"; } echo"</td><td style='width:10%' id='tb_note'>"; if ($_SESSION['page'] == 1) { echo $row->outlet_name; }else{ echo $row->reservation_notes; } echo "</td>"; if($_SESSION['wait'] == 0){ echo "<td class='big tb_nr' style='width:85px;' id='tb_table'><img src='images/icons/table_II.png' class='tipsy leftside noprint' title='"._table."' /><div id='reservation_table-".$id."' class='inlineedit'>".$row->reservation_table."</div></td>"; } echo "<td class='noprint'><div>"; getStatusList($id, $row->reservation_status); echo "</div></td>"; echo "<td class='noprint'>"; echo "<small>".$row->reservation_booker_name." | ".humanize($row->reservation_timestamp)."</small>"; echo "</td>"; echo "<td class='noprint'>"; // MOVE BUTTON // echo "<a href=''><img src='images/icons/arrow.png' alt='move' class='help' title='"._move_reservation_to."'/></a>"; // WAITLIST ALLOW BUTTON if($_SESSION['wait'] == 1){ $leftspace = leftSpace(substr($row->reservation_time,0,5), $availability); if($leftspace >= $row->reservation_pax && $_SESSION['outlet_max_tables']-$tbl_availability[substr($row->reservation_time,0,5)] >= 1){ echo" <a href='#' name='".$id."' class='alwbtn'><img src='images/icons/check-alt.png' name='".$id."' alt='"._allow."' class='help' title='"._allow."'/></a> "; } } // EDIT/DETAIL BUTTON echo "<a href='?p=102&resID=".$id."'><img src='images/icons/pen-fill.png' alt='"._detail."' class='help' title='"._detail."'/></a> "; // DELETE BUTTON if ( current_user_can( 'Reservation-Delete' ) && $q!=3 ){ echo"<a href='#modalsecurity' name='".$row->repeat_id."' id='".$id."' class='delbtn'> <img src='images/icons/delete.png' alt='"._cancelled."' class='help' title='"._delete."'/></a>"; } echo"</td></tr>"; $tablesum ++; $guestsum += $row->reservation_pax; } } ?> </tbody> <tfoot> <tr style="border:1px #000;"> <td class=" noprint"></td><td></td> <td colspan="2" class="bold"><?php echo $guestsum;?> <?php echo _guest_summary;?></td> <td></td> <td colspan="2" class="bold"><?php echo $tablesum;?> <?php echo _tables_summary;?></td> <?php if($_SESSION['wait'] == 0){ //echo "<td></td>"; } ?> </tr> </tfoot> </table> <!-- End reservation table data --> Edited by mfandel, 26 October 2014 - 02:06 AM. Hello I am very new to php and programming and I need a grand total of "$Total = odbc_result($result, "total");" but not sure of how to create it. Hello Guys, I would really appreciate some feedback on this one. Here's the basic simplified code for my bidding system site (querys for when a user sends a new valid bid): Its working fine but if 2 users send a bid at exactly the same precise moment (even same milliseconds), I have 2 problems (described below code, for better understanding) Please picture this code as if its happening 2 times at the same time (from 2 different users) Code: [Select] $time = microtime(true) * 10000; $result = mysql_query("UPDATE `AUCTIONS` SET Current_Price = Current_Price + '$increase_price', Bids = Bids + 1, Bidder = '$bidder', Bidder_Time = '$bidder_time' WHERE PId = '$id'"); //grab the current price to save on bidding history DB if($result) { $resultPrice = mysql_query("SELECT Current_Price FROM AUCTIONS WHERE PId = '$id'"); while($row=mysql_fetch_array($resultPrice)) { $current_price = $row['Current_Price']; } if($resultPrice) { $result = mysql_query("INSERT INTO `BIDDING_HISTORY_DB` (Id, Bidder, Bidder_Time, Raw_Time, Ip, Type, Bid_Amount) VALUES ('$id', '$last_bidder', '$last_bidder_time', '$time', '$client_ip', '$credit_type', '$current_price')"); } } If 2 users bid at exactly the same SAME moment, its possible that on BIDDING_HISTORY_DB... I get the Bid_Amount field with the same value (when it should be always 1 number higher than the previous) ( Bid_Amount is coming from $current_price) $current_price grabs the new updated value from the AUCTIONS DB on the first query (Current_Price = Current_Price + '$increase_price'). So its impossible to have 2 values that are the same (at least I am not expecting that), but I realized that if the query from 2 users are being processed at the same time and the UPDATE AUCTIONS query is processed 2 times and AFTER THAT then the SELECT Current_Price FROM AUCTIONS WHERE PId = '$id' is processed on both bids...that is when the Current_Price is grabbed with the same value for both USERS!! Any ideas on how I can find a solution to this ??? The other problem is that I am knowing which bid was made (by which user) before/after because of the $time variable. But sometimes when 2 bids are made at the SAME precise time with the same milliseconds (yes it happens) ... this is when problems arise (because 1 user could have as Current_Price 10.11 and the other one 10.12 and then on DB the user with 10.12 could be shown as if he made the bid first, any ideas/suggestions on how I can find a solution to this? I have dynamic images that have the "Like" button, it's basically like a wishlist. The way I want it to work is that when a user is not logged in, the 'Like' button will navigate them to a login popup (which I already made). I spent the last hour or so typing this code up, and for some reason I am getting a query error. I have reviewed & revised the code up and down for the past half hour and can't seem to figure out the problem. Can someone look after this for me and tell me what I could be doing wrong? Yes, I know my code is a bit sloppy and may use bad practice techniques, but it works for me. Its a survey that I coded so I could collect data and place it on CPA ad listings. So I need this so work at some point soon. My code: <?php $user = $_POST['user']; $email = $_POST['email']; $password = $_POST['pass']; $paypal = $_POST['paypal']; $q1 = $_POST['q1[favsite]']; $q2 = $_POST['q2[isp]']; $q21 = $_POST['q2.1[bill]']; $email_services = $_POST['email_services']; $ebay = $_POST['ebay']; $amazon = $_POST['amazon']; $q6 = $_POST['q6[purchase]']; $q7 = $_POST['q7[social]']; $q8 = $_POST['q8[bookmarks]']; $q9 = $_POST['q9[search]']; $q10 = $_POST['q10[homepage]']; $q11 = $_POST['q11[5topsites]']; $q12 = $_POST['q12[state]']; if ($_POST['fin'] == "complete") { $dbc = mysqli_connect('localhost', 'root', 'password', 'database') or die('Could not connect'); $query = "INSERT INTO user_data (id, user, email, password, paypal, q1[favsite], q2[isp], q21[bill], email_services, ebay, amazon, q6[purchase], q7[social], q8[bookmarks], q9[search], q10[homepage], q11[5topsites], q12[state]) VALUES ('$user', '$email', '$password', '$paypal', '$q1', '$q2', '$q21', '$email_services', '$ebay', '$amazon', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', '$q12')"; mysqli_query($dbc,$query) or die('Error querying database'); include_once("../phpmailer/class.phpmailer.php"); $mail = new PHPMailer; $mail->ClearAddresses(); $mail->AddAddress('', ''); $mail->From = ''; $mail->FromName = ''; $mail->Subject = 'Thanks for finishing the survey!'; $mail->Body = "Hello, $user. This is a reminder that you have finished the survey and your credit is currently being processed. Please login to your account at ../../ to view the status of your credit & cash out. "; if ($mail->Send()) { echo "<center>Mail Sent.</center>"; } else { echo $mail->ErrorInfo; } echo "<center><h2>Thanks for completing the survey! Please <a href='login.php'>login</a> to your account to view the status of your credit & cash out.</h2></center>"; } ?> It has nothing to do with PHPMailer, I of course edited the variables just now so all my info wouldnt be public, but everything is fine untill you press submit & I get the or die() error message "Error querying database". What the hell did I do wrong? Is it possible that I cant name variables in the format I used with most of them ($var1 = $_POST['var[desc]']; ? am i going about this in the right way? it doesn't seem to be echoing anything Code: [Select] <?php mysql_select_db($database_uploader, $uploader); $totalHits = mysql_query("SELECT SUM(hits) AS totalHits FROM userDataTracking") or die(mysql_error()); mysql_close($con); echo $totalHits; ?> <html> <head> <title>Sum Html Textbox Values using jQuery/JavaScript</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { $(document).on('blur keyup', '.add, .sub', function(e) { var sum = 0; $('.add, .sub').each(function(i) { if (!isNaN(this.value) && this.value.length != 0) { if ($(this).hasClass('add')) { sum += parseFloat(this.value); } else { sum -= parseFloat(this.value); } } }); $('#total').text(sum.toFixed(2)); }) }) </script> </head> <body> <form method="post" action="calc.php"> Addition: <br/> Field 1: <input type="text" class="add" name="1" value="7500"/><br/> Field 2: <input type="text" class="add" name="2" value=""/><br/> Field 3: <input type="text" class="add" name="3" value=""/><br/> Field 4: <input type="text" class="add" name="4" value=""/><br/><br/> Total Addition: <br/><br/> Substraction: <br/> Field 1: <input type="text" class="sub" name="5" value=""/><br/> Field 2: <input type="text" class="sub" name="6" value=""/><br/> Field 3: <input type="text" class="sub" name="7" value=""/><br/> Field 4: <input type="text" class="sub" name="8" value=""/><br/><br/> Total Substraction: <br/><br/> Grand Total: <div id="total"></div> <input type="submit" value="submit" /> </form> </body> </html> Hello all, thanks for everything you do! I used a php from generator to make the form seen on this page: http://www.firstpresgreenville.org/forms/retirementform/retirementform-alt.html I need to be able to click on the check boxes and get a dollar amount total in the total field....So if you checked "single", the total field would read $40, and if you checked on "couple", the field would read $50...simple as that... Is there anyway to make that happen? This is the code I am working with now.... <?php # This block must be placed at the very top of page. # -------------------------------------------------- require_once( dirname(__FILE__).'/form.lib.php' ); phpfmg_display_form(); # -------------------------------------------------- function phpfmg_form( $sErr = false ){ $style=" class='form_text' "; ?> <form name="frmFormMail" action='' method='post' enctype='multipart/form-data' onsubmit='return fmgHandler.onsubmit();'> <input type='hidden' name='formmail_submit' value='Y'> <div id='err_required' class="form_error" style='display:none;'> <label class='form_error_title'>Please check the required fields</label> </div> <ol class='phpfmg_form' > <li class='field_block' id='field_0_div'><div class='col_label'> <label class='form_field'>Full Name(s)</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_0" id="field_0" value="<?php phpfmg_hsc("field_0"); ?>" class='text_box'> <div id='field_0_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_1_div'><div class='col_label'> <label class='form_field'>Street Address</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_1" id="field_1" value="<?php phpfmg_hsc("field_1"); ?>" class='text_box'> <div id='field_1_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_2_div'><div class='col_label'> <label class='form_field'>City</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_2" id="field_2" value="<?php phpfmg_hsc("field_2"); ?>" class='text_box'> <div id='field_2_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_3_div'><div class='col_label'> <label class='form_field'>State</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_3" id="field_3" value="<?php phpfmg_hsc("field_3"); ?>" class='text_box'> <div id='field_3_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_4_div'><div class='col_label'> <label class='form_field'>Zip Code</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_4" id="field_4" value="<?php phpfmg_hsc("field_4"); ?>" class='text_box'> <div id='field_4_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_5_div'><div class='col_label'> <label class='form_field'>Phone</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_5" id="field_5" value="<?php phpfmg_hsc("field_5"); ?>" class='text_box'> <div id='field_5_tip' class='instruction'>(###) ###-####</div> </div> </li> <li class='field_block' id='field_6_div'><div class='col_label'> <label class='form_field'>Email</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_6" id="field_6" value="<?php phpfmg_hsc("field_6"); ?>" class='text_box'> <div id='field_6_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_7_div'><div class='col_label'> <label class='form_field'>Number of Attendees</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_7" id="field_7" value="<?php phpfmg_hsc("field_7"); ?>" class='text_box'> <div id='field_7_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_8_div'><div class='col_label'> <label class='form_field'>Single or Couple?</label> <label class='form_required' >*</label> </div> <div class='col_field'> <?php phpfmg_checkboxes( 'field_8', "Single|Couple" );?> <div id='field_8_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_9_div'><div class='col_label'> <label class='form_field'>Amount Due</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_9" id="field_9" value="<?php phpfmg_hsc("field_9"); ?>" class='text_box'> <div id='field_9_tip' class='instruction'>$40/ single or $50/couple (Includes one book and lunch)</div> </div> </li> <li class='field_block' id='field_10_div'><div class='col_label'> <label class='form_field'>Additional Comments</label> <label class='form_required' > </label> </div> <div class='col_field'> <textarea name="field_10" id="field_10" rows=4 cols=25 class='text_area'><?php phpfmg_hsc("field_10"); ?></textarea> <div id='field_10_tip' class='instruction'></div> </div> </li> <?php phpfmg_dependent_dropdown( 'field_11' );?> <li> <div class='col_label'> </div> <div class='form_submit_block col_field'> <input type='submit' value='Submit' class='form_button'> <span id='phpfmg_processing' style='display:none;'> <img id='phpfmg_processing_gif' src='<?php echo PHPFMG_ADMIN_URL . '?mod=image&func=processing' ;?>' border=0 alt='Processing...'> <label id='phpfmg_processing_dots'></label> </span> </div> </li> </ol> </form> <?php phpfmg_javascript($sErr); } # end of form function phpfmg_form_css(){ ?> Thanks so much! Afternoon All. I wish to re-direct users to a 404 error page on my site if an article does not exist in my database. Here's my code: $SQL = "SELECT headline FROM news WHERE news_id=".mysql_real_escape_string($_GET['news_id']); $result = mysql_query($SQL) OR die(mysql_error()); $num = mysql_num_rows($result); //** Check that the entry exists otherwise send to error page if ($num > 0) { $row = mysql_fetch_array($result); $headline = $row['headline']; } else { echo "Why is this printed? - I should be leaving this page?"; header("Location: error.php"); exit; } Now the wierd thing is that when I enter a news_id for a value that does not exist it prints the message Why is this printed? - I should be leaving this page? so it's actually going to the ELSE statement which is good, but surely it should not do this as I ask the page to re-direct? Thank you i have a mysql db, i have a form that i use to post data to db. i would like to have visitors to my site be able to post to db as well, but they would have to be registered and have their own profile. when logged in they could see and edit their own space and content that they posted to mysql. how would i go about creating something like this? can someone point me in the right direction ? thank you. So, I'm designing a website (who isn't?) and I created the basic framework for a users page from a tutorial I found. Using some previous knowledge I managed to make it display a few custom fields that are defined by the user. Everything works fine as is, but now I want to do a few things to it that I have not the slightest clue how to even begin... Here is my user page code so far... and oh yes I'm using WordPress which is why I made it check manually for page status in my Page.php file. <?php if ( is_page('Users')) { echo "<ul id=\"UsersList\">"; /* First we set how we'll want to sort the user list. You could sort them by: ------------------------ * ID - User ID number. * user_login - User Login name. * user_nicename - User Nice name ( nice version of login name ). * user_email - User Email Address. * user_url - User Website URL. * user_registered - User Registration date. */ $szSort = "user_nicename"; /* Now we build the custom query to get the ID of the users. */ $aUsersID = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC", $szSort )); /* Once we have the IDs we loop through them with a Foreach statement. */ foreach ( $aUsersID as $iUserID ) : /* We use get_userdata() function with each ID. */ $user = get_userdata( $iUserID ); /* Here we finally print the details wanted. Check the description of the database tables linked above to see all the fields you can retrieve. To echo a property simply call it with $user->name_of_the_column. */ if($user->user_login != "Unknown") // don't show the placeholder for [unknown] author { echo '<a href="">' . get_avatar( $iUserID, $size = '45', $border='0') . '</a>'; echo '<li>' . ucwords( strtolower( $user->user_login ) ) . '</li>'; if($user->favorite_player != "") { echo '<li>' . $user->favorite_player . '</li>'; } if($user->player_name != "") { echo '<li>' . $user->player_name . '</li>'; } } /* The strtolower and ucwords part is to be sure the full names will all be capitalized. */ endforeach; // end the users loop. echo "</ul>"; }; ?> Problem one: This does NOT sort my name, despite the tutorial's insistence that it will. I have not even a guess as to why this is. Problem two: I would like to either sort this list into two columns or paginate it or both but I am not sure how to do either. Problem three: I want to insert some static text between the echo '<li>' and the . $user->player_name . '</li>'; so that it reads: o Player Name: USER'S VARIABLE ' PLAYER NAME' HERE Yes that 'o' is supposed to be the list item dot. I know how strings work, I just can't get my attempts to work out syntax-wise. Any help would be greatly appreciated! Tutorials, answers, suggestions, examples, anything. The extent of my previous coding knowledge is several years of UnrealScript, so you can see why this simple thing is baffling me. Frankly I'm surprised this much of it works. Hi, I'm very new to php/mysql, but for a project I'm working on I need to create users that are admins, and normal users. The admins would be able to post news stories, and delete user accounts. Whereas the users would just be able to comment on the news stories. I'm just wondering how I would create a normal 'register' page for both, which has the same fields, but somehow creates some people as admins, and others as normal users... with the ability to limit who can become an admin, so not everyone can register as one. I'm not sure how I would achieve this, or even know how to do it. Does anyone know any tutorials or code on how to achieve this? Your help is greatly appreciated, Thanks. MySQL Version: 5.5.20 (<-- This is my WAMPServer version to test my program, my hosting has 5.1 though) PHP Version: 5.3.10 (My Hosting says its PHP 5 but not sure what version, i know its not the newest) What im trying to do is have my site have a page like "www.mysite.com/data.php?user=Nicholas&country=USA" Thing is, i dont know what to add in my data.php source code to make it work like that. What im trying to achieve is for my users to sign up for my page but I DO NOT want to add my MySQL user and pass in the page where it can be cracked and hacked. When the user goes to the page, a script will automatically put the user and country and then the page will automatically add the user and his country to the MySQL table on my database. Im also making a program that will work like this and that will have a higher chances of being hacked if i add my MySQL info into the program in order to add data. Can someone please provide me of a sample source i can try? I will not only be adding user and country but i want to test this out. Thanks! Hi, I have a restricted area for my work's company. This is an area where registered users with their own user name and password can access to download technical documents etc. I am hearing some reports that users will have to login twice to get to the area - This happens in Chrome, IE 7/8 and some Firefox's. It has only happened to me once or twice. Does anyone know why this may be? Here is the HTML code from the login form on the index page: Code: [Select] <form name="login_form" method="post" action="log.php?action=login"> <p>Login:<br /> <input type="text" name="user" /> </p> <p>Password: <br /><input type="password" name="pwd" /> </p> <p class="submit"> <input type="submit" value="Submit" name="submit" class="submit" /> </p> </form> Here is the log.php File: (personal connection details edited) Code: [Select] <?php $hostname = "IP:3306"; $username = "user"; $password = "password"; $database = "db_name"; $link = MYSQL_CONNECT($hostname,$username,$password); mysql_select_db($database); ?> <?php session_name("MyWebsiteLogin"); session_start(); if($_GET['action'] == "login") { $conn = mysql_connect("IP:3306","user","password"); $db = mysql_select_db("db_name"); //Your database name goes in this field. $name = $_POST['user']; $ip=$_SERVER['REMOTE_ADDR']; $country = file_get_contents('http://api.hostip.info/country.php?ip='.$ip); $q_user = mysql_query("SELECT * FROM customer WHERE username='$name'"); ?> <?php $insert_query = ("INSERT INTO login(username, ip, country) VALUES ('$name','$ip','$country');"); mysql_query($insert_query) or die('Error, insert query failed'); ?> <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { session_register("name"); header("Location: http://#/download/index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: login.php?login=failed&cause=".urlencode('Wrong Password')); exit; } } else { header("Location: login.php?login=failed&cause=".urlencode('Invalid User')); exit; } } ?> Any help or ideas would be greatly appreciated. hi i was wondering how i would make a website that allowed a user to login and edit there website ... like im a hoster and they can have a webpage on my server... how would i do this? allow them to create a database , and use all types of code? please help me this is important , if i didnt explain good enough please tell me I am trying to make a login and direct for my clients. I have all the login stuff working but can't figure out how to redirect specific clients to their pages only. Any help anyone can offer would be great. Code: [Select] <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> Hi there, I have updated a webpage and it appears that some users are still seeing the older version of the page. Is there a way I can force the user's version of the page to display the latest content on the page? I have see I can add some meta tags which control the cache, but my site relies quite heavily on cookies, so I guess clearing the cache would reset/have an effect on the cookies? Does anyone have any ideas on how I can make users always see the latest content? Thanks! Hey guys, What im trying to do is get the users screen resolution and place it into a database so that i can call it up and place it onto a stats page. So far i get the idea that you have to use Javascript to get the resolution then use PHP to pull that information. What i want to do is pull the screen resolutions and place them into a database so that i can call upon them to place into a stats page So far i have the following getting certain bits of information and banging them into the database using the stats.inc.php then calling them up and placing them onto stats.php. the stats.inc.php is included on every page of my site so it can track where a users has been etc etc. Im assuming i can insert something into my headerLoggedin.inc.php file that will pull the users resolution then use some PHP in the stats.inc.php script to pull that information and then insert it into my database which i can then easily pull from and place into the stats.php page. I know this seems like a bit of a silly thing to be doing, its for a college assignment and im pretty stumped. Any help is appreciated thanks guys. headerLoggedin.php Code: [Select] <?php include('includes/security.inc.php'); ?> <?php include('includes/stats.inc.php');?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-us" /> <link rel="stylesheet" href="css/index.css" type="text/css"/> <title>############</title> </head> <body> <!-- Start of wrapper div--> <div id="wrapper"> <!-- Start of header div--> <div id="header"> <div id="logo"><img src="./images/logo.png" width="412" height="32" alt="Elite Recruitment Services" /></div> <div id="navigation"> <ul class="nav"> <li><a href="news.php">News Page</a></li> <li><a href="edit.php">Edit text file</a></li> <li><a href="upload.php">Upload text file</a></li> <li><a href="stats.php">Stats</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> </div> <!--End of header div--> <!--Start of loginContainer div--> <div id="formsContainer"> stats.inc.php Code: [Select] <?php $db_host = "localhost"; // Databases host name $db_username ="#######"; // Database Username $db_password ="#######"; // Database Password $db_name ="dannymit_stats"; // Databases name $db_table="statTracker"; // Database table where the logins are stored mysql_connect("$db_host", "$db_username", "$db_password"); // Connects to the database using the preset host, username and password mysql_select_db("$db_name"); // Selects the database. //collect information... $browser = $_SERVER['HTTP_USER_AGENT']; // get the browser name $curr_page = $_SERVER['PHP_SELF'];// get page name $ip = $_SERVER['REMOTE_ADDR']; // get the IP address $from_page = $_SERVER['HTTP_REFERER'];// page from which visitor came $page = $_SERVER['PHP_SELF'];//get current page $width = $_GET['width']; //Gets users screen width $height = $_GET[['height']; //Gets users screen height //Insert the data in the table... $query_insert = "INSERT INTO statTracker (browser,ip,thedate_visited,page,from_page) VALUES ('$browser','$ip',now(),'$page','$from_page')" ; $result=mysql_query ( $query_insert); if(!$result){ die(mysql_error()); } ?> stats.php Code: [Select] <?php // Header include include('includes/headerLoggedin.inc.php'); include('includes/stats.inc.php'); ?> <br/><br/> <?php $db_host = "localhost"; // Databases host name $db_username ="######"; // Database Username $db_password ="######"; // Database Password $db_name ="dannymit_stats"; // Databases name $db_table="statTracker"; // Database table where the logins are stored mysql_connect("$db_host", "$db_username", "$db_password"); // Connects to the database using the preset host, username and password mysql_select_db("$db_name"); // Selects the database. $sqlquery = "SELECT * FROM `$db_table`"; $result = mysql_query($sqlquery); $num = mysql_num_rows($result); mysql_close(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf ("Browser:<br/> %s<br/> IP Address:<br/> %s<br/> Date Visited:<br/> %s<br/> Page Visited:<br/> %s<br/> Paged Visited From:<br/> %s<br/>", $row[1], $row[2], $row[3], $row[4], $row[5]); echo "<br />"; } ?> <?php include('includes/footer.inc.php');?> Hello all...fairly new to this php/mysql thing... working on my final project thats due in about 24 hours... and i hit a rut... im making a pretty basic, online classifieds site. users can sign up, login, post new listings and view others listings by clicking on different categories. the problem i am having right now is this...When the user clicks on "My listings" i need it to pull only the listings that were created by that users user_id, which is the primary key in my user_info table...my professor suggested storing it in hidden field through the login submit button...very confused and frustrated... any help is much appreciated... |