PHP - Cookie Help (actually Got Code This Time)
Ok I have the following as part of a login script which is supposed to set a cookie upon successful login
[php] if (mysql_num_rows($LoginResult) > 0) { $UserID = mysql_result($LoginResult, 0, 'user_id'); $Id = uniqid(); $IdRes = mysql_query("UPDATE ".MEMBER_LOGIN_TABLE." SET `unique_id`={$Id} WHERE user_id='{$UserID}", $db); setcookie('RAYTH_MEMBER_ID', $Id, time()+2592000); Echo "Logged In. Click <a href='index.php?act=idx'>Here</a> to Continue.<br>Note: If you click continue and you are not logged in please ensure cookies are enabled!"; } [/cookie] However when I log in I get: Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home/rayth/public_html/style.php:1) in /home/rayth/public_html/login.php on line 38 Logged In. Click Here to Continue. Note: If you click continue and you are not logged in please ensure cookies are enabled! Line 38 is the setcookie() line. Can someone shed light on where I am going wrong here? Similar TutorialsHello All I wrote a tiny piece of cookie code (to set and record cookies and hits) that works pretty well but seems to have a bug in it that I cannot figure out. First, here is the code: Code: [Select] <?php $my_cookie = (isset($_COOKIE['my_cookie'])) ? true : false; $countFile = "./data/count.txt"; $cookieFile = "./data/cookie.txt"; $dateTime = date('Y-m-d\,H:i:s\,U\,T\,O\G\M\T'); $remoteIPAddress .= $_SERVER['REMOTE_ADDR']; $remoteUserAgent .= $_SERVER['HTTP_USER_AGENT']; $cookieVal = $dateTime; $cookieVal .= ","; $cookieVal .= $remoteIPAddress; $cookieVal .= ","; $cookieVal .= $remoteUserAgent; $cookieVal .= "\r\n"; if(!$my_cookie){ // read the visit counter $countHandle = fopen($countFile, 'r'); $visitCount = intval(trim(@fread($countHandle, filesize($countFile)))); fclose($countHandle); // incremenet the visit counter $visitCount++; // write the new visit count and cookie value to their respective files $countHandle = fopen($countFile, 'w'); $cookieHandle = fopen($cookieFile, "a+b"); if(!preg_match('/bot/',$remoteUserAgent)){ fwrite($countHandle, $visitCount); fwrite($cookieHandle, $cookieVal); } fclose($countHandle); fclose($cookieHandle); setcookie("my_cookie", $cookieVal, time()+31556926); } else{ // read the visit counter $countHandle = fopen($countFile, 'r'); $visitCount = fread($countHandle, filesize($countFile)); fclose($countHandle); } ?> What is happening is that sometimes, not every time, but, sometimes my cookie.txt count gets a 0 (zero) written back to it and I can't figure out why. Can anybody see anything in there that would have this effect? Like I said, it only gets zeroed out from time to time. Thanks to all for taking the time to read. Hi a get a server error with this code, this worked for awhile, now it doesn't work. I use the first part to extract the user name from the url. then parse it to the IF cookie function as a variable for the cookie name. The cookie is placed on another html page and i placed it like this: <script language="javascript"> document.cookie = "{PROFILE_USERNAME}= 1"; </script> // this code works perfectly i used php to parser the variable to the javascript function, when i check the browser for cookies, it is placed correctly. this code i use to check the cookie's name to see if it exists. the variable below is taken from the url, and matches the username above, but when i execute the code i get this error: Illegal variable _files or _env or _get or _post or _cookie or _server or _session or globals passed to script. can anyone see the problem? <?php $url = $_SERVER['SCRIPT_FILENAME']; $newurl = explode("/", $url); $profmanager=$newurl[6]; $cook= $profmanager; if(!isset($_COOKIE['$cook'])) { $url2 = $_SERVER['HTTP_HOST']; $myurls = 'http://'.$url2.'/'; echo "<META HTTP-EQUIV=Refresh CONTENT=\"0;URL=$myurls\">"; } else { my page code here }?> // to note when i echo the $newurl[6] it does equal the username. the first code in on a html page/the javascript above, // the second code piece is AT THE TOP of a php page. // if there is a better way, liike matching values instead of the cookie name, i would be keen to see it in action. Basically I need to select some rows from my database that have been posted in the last 24 hours. So since my date is stored from the values of the time() function I want to do a query to get the results only greater than a certain time code. So if I lets say have this value: 1321184384, what can I subtract to go back 24 hours? Hi ,
I try to change a PHP code for a booking program without succes. Now the time set is from 00.00 - 24.00hours but it must be fixed on 15.00H ( dropoff) and 11.00H (pick-up). Can someone help me please ?
Big thanks in advance !
$pickhdeftime = !empty($places[$indvrcplace]['defaulttime']) ? ((int)$places[$indvrcplace]['defaulttime'] / 3600) : ''; Hello, The below code works on my home machine.. but not on my Linux machine, I am unable to figure out the problem, please help Code: [Select] require_once("dbconnection.php"); function coun_list() { $rs=mysql_query("select name from timezones") or die(mysql_error()); while($row=mysql_fetch_row($rs)) { $tzone=$row[0]; if($tzone=='Asia/Calcutta') $tzone='Asia/Kolkata'; try { $tz = new DateTimeZone("$tzone"); $lt=$tz->getLocation(); $lat=$lt['latitude']; $lon=$lt['longitude']; echo "$tzone"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } } } coun_list(); I get the below error on my Linux machine, Code: [Select] Caught exception: DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone () Please help me to figure out the issue.. Hey everyone,
So I've been using this code for a while and it may not be the best way of doing things but its worked for me based on my very limited knowledge of PHP. The code is based for a radio station which makes an image change based on the day and time. For some reason though due to daylight savings time ending the code is now off an hour. Whats the best way of fixing this without changing every single number? (Which I actually did try and still seem to be screwing it up) Below is the code:
<p> <?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); //set variable $year to the current year // SUNDAY SCHEDULE if ($d == 0 && $h >= 4 && $h < 5) $img = '/images/shows/HughHewitt.png'; else if ($d == 0 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 0 && $h >= 10 && $h < 11) $img = '/images/shows/MomTalk.png'; else if ($d == 0 && $h >= 11 && $h < 12) $img = '/images/shows/GoodParenting.png'; else if ($d == 0 && $h >= 12 && $h < 14) $img = '/images/shows/PetShow.png'; else if ($d == 0 && $h >= 14 && $h < 15) $img = '/images/shows/GardenRebel.png'; else if ($d == 0 && $h >= 15 && $h < 16) $img = '/images/shows/WorkingMother.png'; else if ($d == 0 && $h >= 16 && $h < 17) $img = '/images/shows/WhatsCooking.png'; else if ($d == 0 && $h >= 17 && $h < 18) $img = '/images/shows/HomeWizards.png'; else if ($d == 0 && $h >= 18 && $h < 19) $img = '/images/shows/DougStephan.png'; else if ($d == 0 && $h >= 19 && $h < 20) $img = '/images/shows/Finance.png'; else if ($d == 0 && $h >= 20 && $h < 21) $img = '/images/shows/PopularScience.png'; else if ($d == 0 && $h >= 21 && $h < 22) $img = '/images/shows/ABCRadio.png'; else if ($d == 0 && $h >= 22) $img = '/images/shows/Medicine.png'; else if ($d == 1 && $h >= 0 && $h < 3) $img = '/images/shows/ArmedAmerica.png'; else if ($d == 1 && $h >= 3 && $h < 4) $img = '/images/shows/HughHewitt.png'; // MONDAY SCHEDULE if ($d == 1 && $h >= 4 && $h < 5) $img = '/images/shows/HughHewitt.png'; else if ($d == 1 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 1 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 1 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 1 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 1 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 1 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 1 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 2 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 2 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 2 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 2 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 2 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 2 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 2 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 2 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 2 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 2 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 3 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 3 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 3 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 3 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 3 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 3 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 3 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 3 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 3 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 3 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 4 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 4 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 4 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 4 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 4 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 4 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 4 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 4 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 4 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 4 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 5 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 5 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 5 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 5 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 5 && $h >= 10 && $h < 13) $img = '/images/shows/BobRick.png'; else if ($d == 5 && $h >= 13 && $h < 16) $img = '/images/shows/DougStephan.png'; else if ($d == 5 && $h >= 16 && $h < 19) $img = '/images/shows/MariluHenner.png'; else if ($d == 5 && $h >= 19 && $h < 20) $img = '/images/shows/DebbieNigro.png'; else if ($d == 5 && $h >= 20 && $h < 22) $img = '/images/shows/DaveRamsey.png'; else if ($d == 5 && $h >= 22) $img = '/images/shows/JoyBrowne.png'; else if ($d == 6 && $h >= 0 && $h < 1) $img = '/images/shows/ShannonJoy.png'; else if ($d == 6 && $h >= 1 && $h < 2) $img = '/images/shows/BillNojay.png'; else if ($d == 6 && $h >= 2 && $h < 4) $img = '/images/shows/DennisPrager.png'; // SATURDAY SCHEDULE if ($d == 6 && $h >= 4 && $h < 5) $img = '/images/shows/DennisPrager.png'; else if ($d == 6 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 6 && $h >= 5 && $h < 10) $img = '/images/shows/RedEyeRadio.png'; else if ($d == 6 && $h >= 10 && $h < 12) $img = '/images/shows/HaidtReport.png'; else if ($d == 6 && $h >= 12 && $h < 13) $img = '/images/shows/ABCNews.png'; else if ($d == 6 && $h >= 13 && $h < 16) $img = '/images/shows/GarySullivan.png'; else if ($d == 6 && $h >= 16 && $h < 18) $img = '/images/shows/PopularTech.png'; else if ($d == 6 && $h >= 18 && $h < 19) $img = '/images/shows/WhatWorks.png'; else if ($d == 6 && $h >= 19 && $h < 21) $img = '/images/shows/JillMoney.png'; else if ($d == 6 && $h >= 21 && $h < 23) $img = '/images/shows/YouManual.png'; else if ($d == 6 && $h >= 23) $img = '/images/shows/MadeAmerica.png'; else if ($d == 0 && $h >= 0 && $h < 1) $img = '/images/shows/MensHealth.png'; else if ($d == 0 && $h >= 1 && $h < 2) $img = '/images/shows/AlanTaylor.png'; else if ($d == 0 && $h >= 2 && $h < 4) $img = '/images/shows/HughHewitt.png'; ?> <img src="<?php echo $img; ?>">Thank You! Kevin I have the following session timeout code which should redirect users of a website to a page (session_expired.php) which prints out a message telling the user that his session has expired. I include this code at the top of every page in the website, that requires user authentication. Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) { // last request was more than 30 minates ago session_destroy(); // destroy session data in storage session_unset(); // unset $_SESSION variable for the runtime header("location: session_expired.php"); } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp ?> The session_expired.php page which I will include below, has a login link, which takes the user to a login page (access_denied.php) Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //Set the page title before the header file $title = 'Session Expired'; require ('header.php'); //need the header ?> <div id="content" class=""> <div id="left_content" class=""> </div> <!--closes left content--> <div id="right_content" class=""> <div id= "right_content_inner_border"> <h5 style ="position:relative;left:660px;top:1px;"> <a style="text-decoration:none" href="access_denied.php">[Login]</a> </h5> <h3 style ="position:relative;left:110px;top:100px; font-color:blue;"> You Session Expired Due to Inactivity! </h3> </div> <!--closes right content inner border--> </div> <!--closes right content--> </div> <!--closes content--> <?php require ('footer.php'); //need the footer ?> Now here lies the problem. When i set the session timeout to say 60 seconds to test the code, everything seems to work perfectly. The authenticated page gets redirected to session_expired.php after 1 minute and when the user clicks on the login link, he is taken back to the login page(access_denied.php). However, when I replace the time with 1800 seconds, the page notice that when I leave the page idle for JUST about 5 minutes, it gets redirected NOT even to the expected session_expired.php page but strangely, directly to the login page(access_denied.php). What could be going wrong here? Any hint is appreciated. I'm kind of a beginner in PHP and I'm not sure how complicated is this thing I need to do so I just need a little bit of help. Anyway, I have this clock counter on a few of my pages, counting down to 0 and what I need to do is execute certain code 15 minutes before a counter reaches 0. It's basically the same code but it needs to run every time one of the counters is 15 minutes away from 0. Any simple way for me to achieve this? Thanks! Hey Guys, I am fixing someone else's code, so please bear with me on this one. Basically the site has an application form and once the user has submitted the form, they get an automated email with an induction date, and the date is taken from the admin panel where the admin user puts in the date and time and number of applicants. So basically the if the admin user puts in Date: 23th Sept 2011 Time: 9:30 Number of Applicants: 30, the next 30 successfull applicants will get that date and time. The problem with the code is that now whenever the user fills in the application and their application is successfull, they are getting an induction date of Thursday, 1 January 1970 and no time. I am not sure why this happens if someone could point me in the right direction. Here is the snipet of the code where it prints out the date: Code: [Select] Your Induction date is <?php echo (date("l, j F Y", strtotime($array_result_ind['date'])))." at ".$array_result_ind['hour'];?> The code at the top of the page is: Code: [Select] <?php //include('browser_redirect.php'); //Start session and page session_start(); $induction = isset($_GET['id'])?$_GET['id']:''; $_SESSION['change_ind_date_app_ID'] = $induction; $db_leafletj_jobs = mysql_connect("localhost", "leafletj_jobs", "t10872") or die(mysql_error()); $sel_leafletj_jobs = mysql_select_db("leafletj_jobs") or die(mysql_error()); $query_str = "SELECT applicants.id, applicants.unique_ref, applicants.app_date, applicants.fname, applicants.surname, applicants.ind_date, applicants.ind_ord_no, inductions.date, inductions.hour FROM (applicants JOIN inductions ON (applicants.ind_date = inductions.date)) WHERE applicants.id=".$induction; $result_ind = mysql_query($query_str, $db_leafletj_jobs) or die(mysql_error()); //$count = mysql_num_rows($result_ind); $array_result_ind = mysql_fetch_array($result_ind, MYSQL_BOTH); ?> Also the database for the induction date and time is blank. I haven't designed the application so I am a little lost. I the system was all working a couple of weeks ago but now all of a sudden it prints out that 1970 date with no time. Is this a quick fix? Thanks, Ken I'm working on a project that has a lot of different timezone options, and all I have from the users is their UTC offset. After weeks of doing tweaks, I come to new issues every time I add something, one would think it would be a lot easier to just get the correct time and day :) The latest issue is that when I try to rewrite a date to a better fomat, it disregards the GMT offset. Like this: 4/14/19, 12:00 PM GMT+2 (=$date) becomes ... 14-04-2019 10:00 when using this code: $bp_date_to_format = date_create_from_format('Y-m-d\TH:i:sP', $date); echo date_format($bp_date_to_format, 'd-m-Y H:i'); I figured it would just rewrite the format, keeping the exact time. It isn't. We do have all these sorts of localization functions as well, but because there doesn't seem to be one single standard (each 3rd party API connection we have uses its own default datetime format so it seems). // Remove UTC Text $UTC_offset = str_replace('UTC', '', $timezone); // Get Offset in Minutes if (stripos($UTC_offset, ':') !== false) { // Calculate seconds from offset list($hours, $minutes) = explode(':', $offset); $seconds = $hours * 60 * 60 + $minutes * 60; } else { $seconds = $UTC_offset * 60 * 60; } // Get User timezone name from seconds $timezone = timezone_name_from_abbr('', $seconds, 1); if ($timezone === false) { $timezone = timezone_name_from_abbr('', $seconds, 0); } // Set new TZ return date_default_timezone_set($timezone);
Isn't there any "one way"solution that can be used? It's confusing to say the least.
Cheers. Code: [Select] <?php if(date('w') == 0) $str = 'today'; else $str = 'last sunday'; $timestamp = strtotime($str); //echo $timestamp; echo "<img src='brn_masthead.gif' width='500' /><br /><table border='1'><tr>"; echo "<tr><td align='center' width='140'><b>Sunday</b></td><td align='center' width='140'><b>Monday</b></td><td align='center' width='140'><b>Tuesday</b></td><td align='center' width='140'><b>Wednesday</b></td> <td align='center' width='140'><b>Thursday</b></td><td align='center' width='140'><b>Friday</b></td><td align='center' width='140'><b>Saturday</b></td></tr><tr>"; $j = 0; for($i = 0; $i < 14; $i++) { $thisdate = date('Y-m-d', $timestamp + ($i * (60 * 60 * 24))); ?> I've looked into mktime and checked the manual, but can't find anything that seems to work inside the loop. Thanks! <?php query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul class="rpul"> <li> <div class="class="post-thumb wp-post-image" style=' '> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </div><div class='cat-post-text'> <h1> <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=322054.0 Hello, I am building an online game(users make a character and move on a map and so on...)
All user data is stored in a mySQL database and I want the users to interact in real-time, but there can be a 1-3 second delay between the communication, but not exceed 3 seconds even if 500 players are playing at the same time.
But for the purpose of the question let's say the users can only chat between one another, if I'll have a solution for that then I can use the same method for more parts of the game.
I can't use websockets because my webhost doesn't support it( I don't want to use pusher.com).
I know I can make real-time apps with ajax long polling, but I think that with 500 players playing at the same time it's not the best solution.
So, finally:
How can I make user interaction as close as possible to a real-time game?
(Without too much load on the hosting server)
(I am sorry if some of my terms are not correct - I am just getting back to coding after a long time...)
Edited by Mythion, 17 August 2014 - 02:34 AM. Hello I am trying to only display results within the time period last sunday too next sunday. my code: Code: [Select] <?php $today = date('Y-m-d H:i:s'); $time = strtotime($today); $last_sunday = strtotime('last sunday', $time); $next_sunday = strtotime('next sunday', $time); $format = 'Y-m-d H:i:s'; $last_sunday = date($format, $last_sunday); $next_sunday = date($format, $next_sunday); ?> <?php $sql_totalsurfs = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, vtp_tracking.Timber, vtp_tracking.Stone, vtp_tracking.Marble, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date>'$last_sunday' AND vtp_tracking.action_date<'$next_sunday' GROUP BY vtp_members.id ORDER BY surfs DESC LIMIT 0, 10"); $rstotalsurfs = mysql_query($sql_totalsurfs); $numrows = mysql_num_rows($rstotalsurfs); ....... Is there and error somwhere in the code? PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. |