Jump to content

Clarkey

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by Clarkey

  1. Make sure the code runs in the <head> section of your HTML. <?php if($something = "something") { echo "<title>my title</title>"; } elseif($something = "somethingelse") { echo "<title>my title 2</title>"; } else { echo "<title>my title 3</title>"; } ?>
  2. There's some great help in this thread but Fastsol, can you explain why a Linode or DigitalOcean VPS wouldn't be capable of this?
  3. Read this, it explains and shows you how it works: http://www.wikihow.com/Create-a-Secure-Session-Managment-System-in-PHP-and-MySQL
  4. PDO is great because it add an abstraction to the database, regardless of the database server type. For instance, if you use mysqli functions throughout your program, and then somebody else deploys the program but they are using postgres database server, then they would have to change every single function that interacts with a database for it to work. But, with PDO, they can just change one variable, and ta daaa!
  5. You've just got to keep going at it.. If you see something you don't understand, research it until you can make sense of it. Think of difference PHP classes / functions that you can create, and then keep trying to improve that class / function until it's solid and super fast. Once I understood the basics of PHP I moved onto learning object orientated PHP and grasped the concept of that. I was then able to study the methods used in popular PHP software packages, such as MVC-frameworks and forums to learn more about them. Just keep coding!
  6. You'd need to do something like this... (this code is not tested) <?php function unread_emails ($username , $password) { $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox,'UNSEEN'); echo count($emails)." "; echo "<pre>".print_r($emails,true)."</pre>"; //die; /* if emails are returned, cycle through each... */ if($emails) { $i=0; /* begin output var */ $output = ''; /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach($emails as $email_number) { $i++; /* get information specific to this email */ $overview = imap_fetch_overview($inbox,$email_number,0); $message = imap_fetchbody($inbox,$email_number,1); /* output the email header information */ $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; $output.= '<span class="from">'.$overview[0]->from.'</span>'; $output.= '<span class="date">on '.$overview[0]->date.'</span>'; $output.= '</div>'; /* output the email body */ $output.= '<div class="body">'.$message.'</div>'; //if{$i==10} break; /* store this email in a database */ try { $dbh = new PDO('mysql:host=localhost;dbname=mydatabase', $dbuser, $dbpass); $sql = "INSERT INTO mytable (email_id, email_date, email_from, email_subject, email_body) VALUES (:email_id, :email_date, :email_from, :email_subject, :email_body)"; $qry = $dbh->prepare($sql); $qry->execute(array( ':email_id' => $email_number, ':email_date' => $overview[0]->date, ':email_from' => $overview[0]->from, ':email_subject' => $overview[0]->subject, ':email_body' => $message )); } catch (PDOException $e) { echo "PDO Error!: " . $e->getMessage() . "<br/>"; } } echo $output; } /* close the connection */ imap_close($inbox); } unread_emails ('**********@gmail.com' , '*******' ); ?>
  7. Ok cool. Mark this thread as answered if your issue is resolved
  8. Advanced Member Shadow_Walker, You say you get the error message of... Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed This means that you are using mysql_* functions that are too old. You need to upgrade to mysqli or PDO. I find it weird that you say the record is deleted, even though you get this error message. I would also suggest in getting into the habbit of putting error checks in place, such as mysql_error() or an exception block when you are developing your scripts, as they are designed to give you insight on why your code hasn't worked. More often that not, you've simply missed a character or something silly like that. In your first post on this thread, the link to delete a record is Delete.php but in your last post, the URL shows Admin_delete.php. What have you changed? I think it's best if you repost your latest code here, with your latest findings and we can help you troubleshoot.
  9. If you look at the code Psycho provided to you, notice how he / she used if(!mysql_num_rows($result)) { to see how many rows have been returned by the query. If you have 0 returned rows, there are no results. It's a simple IF statement
  10. It may not be PHP timing out. The web server that is actually serving the request (probably Apache or NGiNX) may have a 2 minute timeout set.
  11. Try adding the if statement around the add_action function. I have never used the genesis framework so this is just a pure stab in the dark. By the way, the syntax looks weird in your if statement!? if(is_page_template( ,page_blog.php, ) { add_action('genesis_before_content_sidebar_wrap', 'child_before_content_sidebar_wrap'); }
  12. Are you visitors authenticated by a login system? Do you have a session system setup? If so, you can just do a SQL query using a WHERE clause based on some identifier from your $_SESSION array, such as a username or id (depends on how you've set it up) and then get the SQL array and echo them out where they need to go.
  13. Hmm, I'm a little confused... Are you thinking that your visitors user / pass are passed to the mysql function? If so, not at all. You have a special SQL user/pass that your website uses for SQL functions. If you want a login system, then you have to create that, it's completely seperate.
  14. Heed, What usually happens is that you will have a config.php file which contains variables such as <?php $dbhost = "localhost"; $dbuser = "dbusername"; $dbpass = "dbpassword"; $dbname = "mydatabase"; ?> Then, whenever you need to connect to the database in different files, you can use this include statment before your database connect function. <?php include('config.php'); ?> and then your variables will work in that file too. Or, have I completely missed the point here?
  15. Remember to include session_start(); on every page that works with sessions!
  16. Make a new file called logout.php which contains.. <?php session_start(); session_destroy(); print '<meta http-equiv="refresh" content="0;url=http://google.com">'; ?> Then just make a <a href=""> to logout.php EDIT: Didn't read the other replies. If your not doing anything decent with your sessions then this won't work. Read: http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL
  17. $result = mysql_query($query) or die(mysql_error());
  18. Standards say that the <title> tag MUST be in the <head> section of the HTML page. So unfortunately, you will need to add some logic to the head section, wherever that is. EDIT: Have a look in ./includes/egl_inc.php and you will be able to find your way to the header section. I know you stated about SEO, but there is an alternative way to do it using Javascript, but it won't help SEO at all. For example, <script type="text/javascript> document.title = "Test"; </script>
  19. To retain the values in your input boxes, you will need to echo into the 'value' attribute of the input tag. For example, <input value="<?php echo $email ?>"/>
  20. Almost a month delay, sorry! Here is the working script for Googlers reference You can paste it into a file and play around with the dates as it will echo what it is doing. <?php date_default_timezone_set("GMT"); $r = strtotime("03-05-2013 18:00:00"); $n = strtotime("07-05-2013 19:00:00"); //$n = strtotime(date("d-m-Y H:i:s", time())); $rTime = date("H:i:s", $r); $rTyme = date("His", $r); $rDate = date("d-m-Y", $r); $rDay = date("w", $r); $nTime = date("H:i:s", $n); $nTyme = date("His", $n); $nDate = date("d-m-Y", $n); $nDay = date("w", $n); $workdays = array(1,2,3,4,5); $holidays = array("01-01-2013", "29-03-2013", "01-04-2013", "06-05-2013", "27-05-2013", "26-08-2013", "25-12-2013", "26-12-2013", "01-01-2014", "18-04-2014", "21-04-2014", "05-05-2014", "26-05-2014", "25-08-2014", "25-12-2014", "26-12-2014", "01-01-2015", "03-04-2015", "06-04-2015", "04-05-2015", "25-05-2015", "31-08-2015", "25-12-2015", "28-12-2015"); // includes UK bank holidays until end of 2015 echo '-- INPUT<br>'; echo '$r = '.date("D d-m-Y H:i:s", $r).'<br>'; echo '$n = '.date("D d-m-Y H:i:s", $n).'<br>'; echo '<br>-- CHANGES<br>'; # -- $r ------------------------------------- # if $r is before 9am > move to 9am if($rTyme < "090000") { $r = strtotime("9am", $r); echo '$r is before 9am > move to 9am ('.date("D d-m-Y H:i:s", $r).')<br>'; # elseif $r is after 5pm > move to 9am next workday } elseif($rTyme > "170000") { $r = strtotime("+1 weekday 9am", $r); echo '$r is after 5pm > move to 9am next workday ('.date("D d-m-Y H:i:s", $r).')<br>'; } # if $r is a holiday > move to next workday 9am if(in_array(date("d-m-Y", $r), $holidays)) { $r = strtotime("+1 weekday 9am", $r); echo '$r is a holiday > move to next workday ('.date("D d-m-Y H:i:s", $r).')<br>'; # Boxing Day Check if(date("d-m", $r) == "26-12" || date("d-m-Y", $r) == "28-12-2015") { $r = strtotime("+1 weekday 9am", $r); echo '$r is boxing day > move to next workday ('.date("D d-m-Y H:i:s", $r).')<br>'; } } # if $r is a weekend > move to next workday 9am if(!in_array(date("w", $r), $workdays)) { $r = strtotime("+1 weekday 9am", $r); echo '$r is a weekend > move to next workday ('.date("D d-m-Y H:i:s", $r).')<br>'; # Holiday Check if(in_array(date("d-m-Y", $r), $holidays)) { $r = strtotime("+1 weekday ".date('H:i:s', $r)."", $r); echo '$r is a holiday > move to next workday ('.date("D d-m-Y H:i:s", $r).')<br>'; } } # -- $n ------------------------------------- # if $n is before 9am > move to 9am if($nTyme < "090000") { $n = strtotime("9am", $n); echo '$n is before 9am > move to 9am ('.date("D d-m-Y H:i:s", $n).')<br>'; # elseif $n is after 5pm > move to 5pm } elseif($nTyme > "170000") { $n = strtotime("5pm", $n); echo '$n is after 5pm > move to 5pm ('.date("D d-m-Y H:i:s", $n).')<br>'; } # if $n is a holiday > move to last workday 5pm if(in_array(date("d-m-Y", $n), $holidays)) { $n = strtotime("-1 weekday 5pm", $n); echo '$n is a holiday > move to last workday ('.date("D d-m-Y H:i:s", $n).')<br>'; # Boxing Day Check if(date("d-m", $n) == "26-12" || date("d-m-Y", $n) == "28-12-2015") { $n = strtotime("-1 weekday 5pm", $n); echo '$n is boxing day > move to last workday ('.date("D d-m-Y H:i:s", $n).')<br>'; } } # if $n is a weekend > move to last workday 5pm if(!in_array(date("w", $n), $workdays)) { $n = strtotime("-1 weekday 5pm", $n); echo '$n is a weekend > move to last workday ('.date("D d-m-Y H:i:s", $n).')<br>'; # Holiday Check if(in_array(date("d-m-Y", $n), $holidays)) { $n = strtotime("-1 weekday 5pm", $n); echo '$n is a holiday > move to last workday ('.date("D d-m-Y H:i:s", $n).')<br>'; } } echo '<br>-- OUTPUT<br>'; echo '$r = '.date("D d-m-Y H:i:s", $r).'<br>'; echo '$n = '.date("D d-m-Y H:i:s", $n).'<br>'; echo '<br>-- INPUT DIFFERENCE<br>'; $diff = ($n - $r); echo 'Difference in seconds is '.$diff.'<br>'; # work out hours, mins, secs # if $diff is negative > set to 0 if($diff < 0) { $diff = 0; $h = 0; $m = 0; $s = 0; echo '$diff is negative > set to 0<br>'; } echo '$n - $r = '.($n - $r).'<br>'; $h = (int)($diff / 3600); $m = (int)(($diff - $h*3600) / 60); $s = (int)($diff - $h*3600 - $m*60); echo ''.$h.'h '.$m.'m '.$s.'s<br>'; echo '<br>-- LOOP<br>'; $r12 = strtotime("12pm", $r); $n12 = strtotime("12pm", $n); $daysBetween = ceil(abs($n12 - $r12) / 86400); echo '$daysBetween = '.$daysBetween.'<br>'; if($daysBetween == 0) { // do nothing } elseif ($daysBetween == 1) { echo 'Loop stage: '.date("d-m-Y H:i:s", $r).'<br>'; # if $r is a valid workday and not a holiday if(in_array(date("w", $r), $workdays) && !in_array(date("d-m-Y", $r), $holidays)) { # remove 16 hours $diff-=57600; echo ' > Removed 16 hours (is a valid day) for '.date("d-m-Y H:i:s", $r).'<br>'; } else { # remove 24 hours $diff-=86400; echo ' > Removed 24 hours (isn\'t a valid day) for '.date("d-m-Y H:i:s", $r).'<br>'; } } elseif ($daysBetween >= 2) { for($i=0;$i<$daysBetween;$i++) { echo 'Loop stage: '.date("d-m-Y H:i:s", $r).'<br>'; # if $r is a valid workday and not a holiday if(in_array(date("w", $r), $workdays) && !in_array(date("d-m-Y", $r), $holidays)) { echo ' > Removed 16 hours (is a valid day) for '.date("d-m-Y H:i:s", $r).'<br>'; $diff-=57600; } else { # remove 24 hours $diff-=86400; echo ' > Removed 24 hours (isn\'t a valid day) for '.date("d-m-Y H:i:s", $r).'<br>'; } $r = strtotime("+1 day", $r); } } echo '<br>-- OUTPUT DIFFERENCE<br>'; echo 'Difference in seconds is '.$diff.'<br>'; # work out hours, mins, secs # if $diff is negative > set to 0 if($diff < 0) { $diff = 0; $h = 0; $m = 0; $s = 0; echo '$diff is negative > set to 0<br>'; } echo '$n - $r = '.($n - $r).'<br>'; $h = (int)($diff / 3600); $m = (int)(($diff - $h*3600) / 60); $s = (int)($diff - $h*3600 - $m*60); echo ''.$h.'h '.$m.'m '.$s.'s<br>'; ?>
  21. Thanks for all your input guys! I've taken all your approaches and have come up with my own script. I'll post it up once I've tested it for every scenario and optimized it. Thanks again! I really didn't think I was going to get my head around this!
  22. Your right. For example, if you do array('start'=>'2013-02-19 08:45:00', 'end'=>'2013-02-19 10:30:00') it should be still 1.5hr but it does 1.75hr.
  23. Jessica, your an actual star and little bit of a life saver. It works perfectly. I'd much rather understand your thought process than just copy your code, so comments would be great!
  24. Jessica, I played around with what you provided but still don't understand how it works to be honest so I can't adapt it. I've spent a few days on this now, and come to the conclusion that I hate dates and times I just can't work out the logic! Like, how do you know where to start!? Yes, I want any time outside of M-F 9-5 excluded from the calculation, and would prefer the end number to be in seconds so I can calculate the hours, minutes and seconds easier to display it like "16h 25m 44s". Any more input would be appreciated.
×
×
  • 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.