Jump to content

QuickOldCar

Staff Alumni
  • Posts

    2,972
  • Joined

  • Last visited

  • Days Won

    28

Everything posted by QuickOldCar

  1. Are you letting users upload and extract zip files? That's something I would never trust. I'd run them through a virus scanner and also be looking for malicious code if I was to even attempt that. rmdir() is a scary function. Be sure to have a failsafe directory name...even if will never exist...so never has an empty folder value. You don't want to lose more than you want to.
  2. It shows it like so, is what I would try. If offline { "stream": null, "_links": { "self": "https://api.twitch.tv/kraken/streams/test_channel", "channel": "https://api.twitch.tv/kraken/channels/test_channel" } }
  3. Am I correct in saying that an _id will always exist? I don't believe that determines being live or not. Looking at the api I see... "stream": null, So check if steam is null to determine offline. https://github.com/justintv/Twitch-API/blob/master/v2_resources/streams.md
  4. You want to check for if it's not null instead. if (!empty($mydata['_id'])) to if ($mydata['_id'] != null)
  5. About your base64 images for bullets, stick to css for styling. Example: http://jsfiddle.net/leaverou/ytH5P/
  6. To include js you just add the script tag and it's src <script src="javascript-code.js"></script> I happen to use a similar php templating as you do in a cms I created. There is dynamic content through the header,toolbars,sidebar and content area. I use an actions and page controller to determine what loads. ( Whitelisting approach) Additionally the individual pages are blocked from direct access. Providing you do not call a session_start(); on individual pages but only through your index page...Place this the top of each included page. if(!session_id()){ header("Location: http://".$_SERVER['HTTP_HOST']); exit; } index.php <?php //define $server_host = "http://" . $_SERVER['HTTP_HOST']; $document_root = $_SERVER['DOCUMENT_ROOT']; $directory_path = dirname(__FILE__) . DIRECTORY_SEPARATOR; $site_url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER['QUERY_STRING'])) { $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $site_url .= "?" . $query_string; } require_once($directory_path . "/includes/session.php"); require_once($directory_path . "/header.php"); require_once($directory_path . "/topbar.php"); ?> <div id="page-wrap"> <div id="inside"> <div id="header"> <!--tabs--> <?php require_once($directory_path . "/actions.php"); ?> </div> <!--sidebar--> <div id="right-sidebar"> <?php require_once($directory_path . "/sidebar.php"); ?> </div> <!--main-content--> <div id="main-content"> <?php require_once($directory_path . "/controller.php"); ?> </div> </div> </div> <div style="clear: both;"></div> <!--footer--> <div id="footer"></div> <?php require_once($directory_path . "/footer.php"); ?> <div style="clear: both;"></div> <p id="spacer"></p> <br /> </body> </html> actions.php <?php //page navigation tabs and actions control //unwanted tabs shown $unwanted_tabs = array( "users_active" ); //standard tabs $action_array = array( "services", "articles", "help" ); //user logged in tabs $user_action_array = array( "account", "messages" ); //admin tabs $admin_action_array = array( "users", "users_active" ); //user tabs if logged in if ($session->logged_in) { $action_array = array_merge($action_array, $user_action_array); } else { $action_array[] = "register"; } //admin only if ($session->isAdmin()) { $action_array = array_merge($action_array, $admin_action_array); } //static tabs echo "<a class='glass' href='" . $server_host . "'>Home</a>"; //dynamic tabs foreach ($action_array as $actions) { if (!in_array($actions, $unwanted_tabs)) { echo "<a class='glass' href='" . $server_host . "/?action=" . $actions . "'>" . ucfirst($actions) . "</a>"; } } ?> controller.php <?php /* actions and page controller parameter and page inclusion protection */ //only allow these GET paramters to pass in code $allowed_get = array( "action", "user", "id", "page" ); //loop get requests and remove any unwanted ones if (isset($_GET)) { foreach ($_GET as $key => $value) { if (!in_array($key, $allowed_get)) { unset($_GET[$key]); } } } //default page displayed if all else fails $page = "home.php"; /* loop through action array to determine destination $action_array located in actions.php, if action value is not in the array it won't load */ if (isset($_REQUEST['action'])) { if (in_array($_REQUEST['action'], $action_array)) { switch ($_REQUEST['action']) { case "home": //$page = "home.php"; header("Location: ".$server_host); exit; break; case "services": $page = "articles.php"; break; case "articles": $page = "articles.php"; break; case "help": $page = "articles.php"; break; case "register": $page = "register.php"; break; case "account": $page = "account.php"; break; case "messages": $page = "message.php"; break; case "users": $page = "users.php"; break; default: //$page = "home.php"; header("Location: ".$server_host); exit; } } } //include the page only if it exists if (file_exists($page)) { require_once($page); } else { header("Location: ".$server_host); exit; } ?>
  7. While it is not necessary to always use a semicolon the end of php statements...I always put them there out of habit. <?php previous_post_link('%link', '<img src="http://localhost/website.gif" alt="Previous" />', true); ?>
  8. You want to replace one character with another. You can explode the string and do replaces that way. str_ireplace() or preg_replace() I chose another way. <?php $text = "A test string to see the output of this replace."; $loweralpha = range('a', 'z'); $upperalpha = range('A', 'Z'); $alpha = array_merge($loweralpha,$upperalpha); $replace = array('Z','E','B','R','A','S','C','D','F','G','H','I','J','K','L','M','N','O','P','Q','T','U','V','W','X','Y','Z','E','B','R','A','S','C','D','F','G','H','I','J','K','L','M','N','O','P','Q','T','U','V','W','X','Y'); echo strtr($text, array_combine($alpha, $replace)); ?> Returns Z QAPQ PQOFKC QL PAA QDA LTQMTQ LS QDFP OAMIZBA.
  9. Ever think about processing data background a cron and cache results? It seems to me from your other posts no matter what you do live for a client is gonna take too long. Maybe even break the process up more, does this data infinitely grow over time? If it's something that struggles the server or takes too long it probably shouldn't be done that method. You may want to rethink your application and grab particular data only when need it. How about to process all old information and cache results, then only merge new information as needed. I still don't know your entire application.....but you can create a que system that could track smaller tasks and if all competed. When entire jobs are completed it removes from the que. I imagine a que system for both jobs and tasks control when jobs are started, either by cron or on demand define a tasks list per job, save number of tasks to be completed create a cron to cycle all jobs in job_que, check for all tasks completed if all tasks that job completed remove from job_que if all tasks that job not completed and a task not currently running... start lowest sequential task not completed add job to job_que start job mark job as running mark which task started add task to tasks_que start lowest sequential task number to be processed mark task as running process... task ends and marks task as completed if task completed continue next task if is one if no more tasks mark job completed and remove from job_que
  10. A demo script of how you can do it <?php //dummy data to simulate row information from database $row = array( "rights" => "mod" ); echo "<form action='' id='my_form' method='POST'>"; echo "<select name='rights'>"; //rights array $rights = array( "admin", "mod", "user" ); //check if post set and use that, if not use row value if (isset($_POST['rights']) && trim($_POST['rights']) != '') { $selected_rights = trim($_POST['rights']); } else { $selected_rights = $row['rights']; } //loop the rights array with the proper selection selected foreach ($rights as $permission) { if ($selected_rights == $permission) { echo "<option value='" . $permission . "' selected='selected'>" . $permission . "</option>"; } else { echo "<option value='" . $permission . "'>" . $permission . "</option>"; } } echo "</select>"; echo "<input type='submit' name='submit' value='Submit'>"; echo "</form>"; ?>
  11. If you need to secretly send the information to a 3rd party site but keep that user your own site. Use curl and send it POST with the information from your form. This is the basic idea, if you need to filter or sanitize any post data can do that before and pass your new array. <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://somesite.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, count($_POST)); $fields = http_build_query($_POST); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); $contents = curl_exec($ch); curl_close($ch); ?>
  12. Why not use a free web text editor such as ckeditor or tinymce It makes adding articles so much easier.
  13. You either want to use the span tag or do additional css for it. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
  14. It's not all of a sudden, has been deprecated since 5.3 and removed in 5.4 Read here for some help, it really depends what's being used in your code the amount that needs to be changed. http://php.net/manual/en/faq.misc.php#faq.misc.registerglobals
  15. It's your temp directory. Use this to see where yours is located. echo sys_get_temp_dir();
  16. I think you missed a parenthesis at the end. $serie1->addPoint(new Point($prices[$i]['date'], $prices[$i]['price']));
  17. ftp_get() or ftp_fget() depending what you want to do. Look at the 5th parameter which is resumepos
  18. Is hard to toss out good advice without knowing the entire workings of your database design. Did you know you can directly access the data without triple looping foreach($firstArray['row1']['dates'] as $key => $value) { //whatever want to do with it }
  19. Use timestamp. 2014-10-09 09:31:41 what timesone is that? am or pm? I've seen it both ways, do both if you want. If another server wanted to store the data their database a timestamp is better. If they want to grab your data and display it, timestamp still works with minimal effort. If they get a formatted date, they have to parse it or run through strtotime and back to date. Consider american, european and iso formatting differences American M/D/Y European D-M-Y ISO Y.M.D. I've seen uk sites format their dates on output to slashes and their orders. Timestamp is always right because is utc, set the locale, what parts want to display as a date and are done. When it comes down to it...timestamp is the best choice.
  20. Unless you start adding items in a sub directory. You can also do something like this $server_host = "http://".$_SERVER['HTTP_HOST']; echo "<script type='text/javascript' src='".$server_host."/cms/jquery/jquery.js'></script>"; <script type="text/javascript" src="//<?php echo $_SERVER['HTTP_HOST'];?>/cms/jquery/jquery.js"></script>
  21. you were also missing a < in <body> Try this...I even tested it. <!DOCTYPE html> <html> <title>login_redirect.</title> <head> <script type="text/javascript" language="javascript"> function redirectForm() { document.getElementById("form-redirect").submit(); } </script> </head> <body onLoad="redirectForm();"> <form id="form-redirect" action="http://mysite.com/page2.php" method="post"> <input type="hidden" name="mac" value="13565126262" /> </form> </body> </html> as a self test use this <?php if(isset($_POST['mac'])){ echo $_POST['mac']; die(); } ?> <!DOCTYPE html> <html> <title>login_redirect.</title> <head> <script type="text/javascript" language="javascript"> function redirectForm() { document.getElementById("form-redirect").submit(); } </script> </head> <body onLoad="redirectForm();"> <form id="form-redirect" action="" method="post"> <input type="hidden" name="mac" value="13565126262" /> </form> </body> </html>
  22. Additionally... use exit(); or die(); directly after header redirects to stop the rest of code from continuing header('Location: page3.php'); exit();
  23. What is this? value="$(mac)" No idea why you are doing js redirects and all those pages Make a file called process.php or something and do all the php logic in there with header redirects Separate logic from html Don't just assign a variable to a request Check if it exists and make sure is not empty if(isset($_POST['mac']) && trim($_POST['mac']) != ''){ $_SESSION['macid'] = trim($_POST['mac']); } mysql_* functions are deprecated, suggest using PDO or mysqli_* functions You need to filter/sanitize or escape anything that gets inserted to your database filter checking ctype data If you use PDO it can escape when using prepared statements. Using mysqli_ is mysqli_real_escape_string()
  24. if this is a login shouldn't you not include "AND Activation IS NULL" to the end of your query Instead in the session creation can make a check Change this according to your logic if($role['activation'] != NULL){ $_SESSION['user_logged'] = true; }
×
×
  • 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.