Jump to content

QuickOldCar

Staff Alumni
  • Posts

    2,972
  • Joined

  • Last visited

  • Days Won

    28

Everything posted by QuickOldCar

  1. if($_SERVER['REMOTE_ADDR'] == "203.135.37.204"){ include("scripta.php"); } else { include("scriptb.php"); }
  2. I guess you are asking about seo rewrite rules
  3. Sure is not power saving mode or screensaver? You can set them all to never in advanced power settings, this goes for harddrives or any other device as well. Blank screens usually indicates a power issue or video problem. If you unplug the drive the machine should boot and see something on screen. Unplug all additional devices plugged into the motherboard and see if can boot it. Test one memory stick at a time If you plug something in such as a cdrom or harddrive and pc suddenly fails you found your issue. You can try doing a check disk on a drive http://technet.microsoft.com/en-us/magazine/dd637756.aspx You can't run this on a drive that is currently in use Try pressing F8 while booting and select Commannd Prompt This is a good command that can repair messed up os or lost files, tries to repair and fix bad sectors. chkdsk /r C: you can also try this within windows search for cmd (command prompt) right click the icon and select "run as administrator" type: sfc /scannow A lot of times smart status fails on a drive, you can disable smart status checking in bios
  4. That's if the OP want's to do geolocation
  5. The form needs a lot more work. The next step would be checking POST values, right now default is GET because the method is not set in the form. Next can insert them into a database I was making a lot of fixes but got called into work today. Do some reading on PDO and prepared statements, is what we will be using
  6. I think it would be interesting and useful to many to make a do and don't section or pinned post for most sections. Editable by admins and mods to keep organized Like the phpfreaks bible of coding, best practices. A lot of members post some valuable information that gets lost old posts or too hard to search for. Everyone repeating themselves on bad practices or deprecated code, turning on error reporting and such.
  7. Well with any book or tutorial is sometimes not the best way or bad practices. I read an older version many years ago, hopefully they changed a lot of it. If you use it as a beginners guide and not a bible while continuing to learn will be ok. Sometimes even comes down to preferences of the programmer. Here are some of mine and personal advice. Turn on error reporting and display all errors during development, log the errors in production sites. We are in the era of PDO and prepared statements, if have the choice go PDO It's good to get familiar with old or outdated code so you can spot it or know how to fix it. Get your full idea planned out in steps, figure out how you may go about it, see if is any alternate or better ways. If is any trouble areas...try to work those out first to see if is feasible. Failing at something is also learning, don't get stressed or upset. Sometimes a few minutes of thought can save you hours/days/months of headaches later on. I prefer procedural over oop most of the time. Resembles a lot of other coding languages that have been doing for 35 years and makes me more proficient oop has it's uses though, so would be good to learn it once get a firm grasp on procedural Please don't mix oop and procedural. I heavily comment to remind myself years later or possibly someone else Also handy to comment end braces if need to add or remove some code there Name variables, functions, classes, methods, etc relative to what they actually are, not meaningless letters and numbers that anyone but you knew what they stood for at the time. I prefer to use _ for $mulitple_variable_names and Upper first letter multiple words for myFunctionNames Do lots of spacing to try and organize or section the code Don't make functions if know are only gonna use it once or just to include it. Piles of includes is bad. Never iframe, file_get_contents or curl something from your own site, just include it. Although require_once may be a tad slower it makes the code a lot less prone to errors, if write code well use include Relative paths seems like is more efficient and easier...but can cause many issues, I'll take absolute urls and full paths any day. Try not to do that spaghetti code coming in and out of html and php, logic then display, do all processing above and html on the bottom. Function before beauty is my style. make sure it all works, then dress it up, you may scrap the idea and wasted time. If you need to make a search index for your defines...you probably did it wrong. Always check if a variable is set before using it. Define empty arrays prior to questionably using them. Trimming a variable will ensure is no unwanted whitespace Don't come up with your own security rules unless you absolutely know what are doing, use tried and proven methods. Store sensitive data a non public folder Never store plaintext passwords, not in cookies,sessions,file or database, not ever Don't repeat yourself, if a function or making an array will save you lots of repetitive code, by all means do it. If you have a page full of elseif's, a switch is probably better Look into data normalization UTF-8 is your friend The ci in database collations means case insensitive, use it Even better...don't uppercase databases, columns or tables in the database Always filter/sanitize/escape anything going into your database check for exact data types you expect Don't use for or foreach loops with mysql results, that's what while is for Don't so sql queries in loops. If you have to do a few sql queries to get some data, you can most likely use join or rewrite your query Don't select * in a query unless you plan to use it all, otherwise only fetch what are going to use For mysql query results, fetch_array will return the numeric index and also associative array , if you don't need the numeric index use fetch_assoc because will only be the associative array There was a few rare instances where I had to use $_REQUEST, try to use the servers request type you selected Additional checking for errors within your code is helpful Never output anything before header() Register globals was never good to use Print or echo, I always use echo because it can do more and why bother to mix them Use print_r to show a pretty array just to check code works, var_dump is more useful Stick with full <?php ?> tags as <? ?> short tags not always enabled on servers. Always use curly braces, will help maintain your code better and not forget when actually need one. I personally use four spaces for indentation Use a good ide or coding editor with color highlighting and formatting, I use notepad plus One line per statement is fine, more readable code, don't jumble it all up one line. Single quote,double quote, types of concatenation, I usually stick to doubles and use curly braces, but sometimes not if am sure will be no variables. Don't use addslashes. Don't use $_SERVER['php_self'], forget it exists. Quote your variable keys That's all I have for now, am sure I missed many.
  8. It gets tiresome after a while, I've been at it many years and spent many sleepless days in a chair. What keeps me going is a few projects that interest me. Using your brain a lot is sometimes more stressful than manual labor.
  9. Is never a need to iframe content from your own website. You have no control with iframes, the same amount someone else does if iframed it. If you want dynamic content like you say use ajax or jquery. Instead of iframes and 4 submits, you should have one form with one submit. Check the post parameters and handle the data for output as needed.(like include a script)
  10. You need to integrate paypal with prices. Most likely need paypal pro Keep all the files in a folder users have no access to, generate a new download file and link that expires protect download links
  11. You had everything within the loop, so it showed every time Added some css, you can style it additional <style type="text/css"> .tg {color:black;border-collapse:collapse;border-spacing:0;} .tg td{color:red;font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg th{color:green;font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} </style> <?php $conn = new mysqli($servername, $username, $password, $dbname); $sql = "SELECT deadchar, level, class, killforumid, realm, date FROM pkdata ORDER BY deadchar DESC"; $result = $conn->query($sql); echo " <table class='tg'> <tr> <th class='tg'>Victim</th> <th class='tg'>Level</th> <th class='tg'>Class</th> <th class='tg'>Killer</th> <th class='tg'>Realm</th> <th class='tg'>Date</th> </tr>"; while($row = $result->fetch_assoc()) { $deadchar = $row['deadchar']; $level = $row['level']; $class = $row['class']; $killforumid = $row['killforumid']; $realm = $row['realm']; $date = $row['date']; echo " <tr> <td class='tg'>$deadchar</td> <td class='tg'>$level</td> <td class='tg'>$class</td> <td class='tg'>$killforumid</td> <td class='tg'>$realm</td> <td class='tg'>$date</td> </tr>"; } echo '</table>'; $conn->close(); ?>
  12. Can go either way with it. If you went cloud based hosting you can keep upping all your specs as needed it. ovh.com , Amazon EC2 , google cloud mesosphere The Mesosphere Datacenter Operating System (DCOS) is a new kind of operating system that spans all of the servers in a physical or cloud-based datacenter, and runs on top of any Linux distribution. Since you mentioned weebly as to maybe hosting websites...take a look at wordpress and the multisite network. They have the hyperdb plugin to do multiple databases Can also do virtualization with openvz or xen and create virtual dedicated or virtual private servers I'll mention kvm as well To name a few virtual machine admin panels VirtKick Your self-hosted VPS panel, similar to DigitalOcean archipel Archipel is a solution to manage and supervise virtual machines. solusvm Powerful UI Based VPS Management Software hypervm The Most Complete Virtualization Manager. Manage your entire server cluster from a single console. (never liked it using old distros) feathur Feathur is a VPS control panel based on PHP.
  13. Might as well link to and learn PDO , they have some examples there, be a better start.
  14. If you want to include other files in certain scripts should add elseif or a switch in just those included scripts. (makes it easier to do as well) Do the check for the url parameter as shown in the script below....but only in pages you need it. Made this anyway for you to try and look at. This includes the links pages only if news is set Is more complicated because I added the switches so can rename url parameters or the included file names (I kept them named the same in example) <?php $x_pages = array( "home", "about", "news" ); $r_pages = array( "link1", "link2", "link3" ); //loop x as href links foreach ($x_pages as $x) { echo "<a href='?x=$x'>$x</a> "; } //GET x from address bar //only allow one that's in x_pages array if (isset($_GET['x']) && in_array(trim($_GET['x']), $x_pages)) { $x_location = trim($_GET['x']); } else { $x_location = 'home'; //default location } //assign the files name to parameter value switch ($x_location) { case "home": $x_filename = "home"; break; case "about": $x_filename = "about"; break; case "news": $x_filename = "news"; break; }//end x_location switch echo "<h2>" . ucfirst($x_location) . "</h2>"; //include a page $x_script = dirname(__FILE__) . DIRECTORY_SEPARATOR . $x_filename . ".php"; if (file_exists($x_script)) { include($x_script); //link pages only included in news if ($x_location == "news") { if (isset($_GET['r']) && in_array(trim($_GET['r']), $r_pages)) { $r_location = trim($_GET['r']); } else { $r_location = "link1";//default link page } echo "<div>"; foreach ($r_pages as $r) { echo "<a href='?x=news&r=$r'>$r</a> "; } echo "</div>"; echo "<h2>" . ucfirst($r_location) . "</h2>"; switch ($r_location) { case "link1": $r_filename = "link1"; break; case "link2": $r_filename = "link2"; break; case "link3": $r_filename = "link3"; break; } //end r_location switch //include link pages $r_script = dirname(__FILE__) . DIRECTORY_SEPARATOR . $r_filename . ".php"; if (file_exists($r_script)) { include($r_script); } else { echo "$r_script does not exist."; } } //end if get news } else { echo "$x_script does not exist."; } ?> To learn about functions
  15. Personally I always thought web apps were a waste, especially since most phones now can view web pages a lot better now. You can make nice mobile capable sites these days, some screen size discovery is harder now with the huge phones and tablets. It sounds like you need to make an api Include any extensions/library or code need for particular tasks. json data usually works out well a few languages, I would try to make anything you have output to that. As for escaping, let pdo do the work mostly, but you can match anything as for tags,scripts,bad words and such and filter them out. A way to grab the extension, some files have to download at least a partial of it to find out what it really is. $url = "http://mysite.com/file/greatsong.mp4"; $ext = array(); $ext = end(explode(".",$url)); if(!empty($ext)){ echo $ext; } You can't always rely on extensions as being safe, as an example is viruses embed into pdf files There is mp4 video and audio, without the mime type is unknown Images generated with gd or through a script could have no extension unless downloaded a partial of it and find out what it is. I parse pages a lot with dom, simplexml or preg_match
  16. Doesn't this throw and error as well? $ses_sql = mysql_query("select username from login where username ='$user_check", $connection);
  17. Wouldn't be much sense trying to get it into php since already is html. You can echo javascript code out providing it's escaped properly. This... echo '<span class="notification">'.'<font color="red">*</font>'.'&nbsp'."Sentence"."<br>".'<br>'; could easily become... (besides all the unnecessary concatenation, font is deprecated long ago, use style directly or css rules) echo "<span class='notification' style='color: red;'> * Sentence </span>"; or echo "<p class='notification'><span style='color: red;'> * </span> Sentence</p>";
  18. I suppose showing the form code would have helped. if(empty($errors)){ //process script } else { //show form, show errors or can add these php snippets into form to show errors if(isset($errors['name'])){ echo $errors['name'],"<br />"; } }
  19. Must be my slow internet or the site, ha ha.
  20. Or hold all the errors into a single array as NotionCommotion did. It depends if want to do specific checks on the errors or just show something
  21. Hello to you as well. If are storing errors in $errors array you can just add to it something like this $errors = array(); if (empty($_POST["name"])) { $errors['name'] = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $errors['name'] = "The form of the name entered is not acceptable"; } }
  22. You can install an amp stack and have a local server running for development or can even set it live. xxampp (windows,linux,mac os) wamp (windows) lamp (linux) each distro has own install methods mamp (mac os) Is some other versions but are a pain to install, no longer supported or solaris,ibm Once you have something can work with stop back and ask particular questions, lots here are willing to help. Take a look at php.net for some additional info, tutorials, example codes Notepad plus is a nice editor with highlighting
  23. Welcome Jarrod They still sell that book? Hopefully you'll learn better practices here. Here is the best place to learn php, browse through it as if you never read that book. php.net tutorial Familiarize yourself with the extensions and their functions, is plenty of examples there. http://php.net/manual/en/extensions.alphabetical.php
  24. I recommend using imagepng To retain transparency throughout multiple layers you need to use imagealphablending and imagesavealpha And be sure to use imagedestroy to free the memory of images created
  25. You can add that same as would in html but before or after the <?php ?> tags It's possible to break in and out of php to html js script can go here <?php //php code ?> js script can go here <?php //php code ?> js script can go here Best place to put items like this is in a script that always gets included into every page, like your header file. Here is the prosilver template in phpbb 3.1.2 Located in styles/prosilver/template/overall_header.html I added the script within the <head></head> tags <!DOCTYPE html> <html dir="{S_CONTENT_DIRECTION}" lang="{S_USER_LANG}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width" /> {META} <title><!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> <!-- IF S_ENABLE_FEEDS --> <!-- IF S_ENABLE_FEEDS_OVERALL --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {SITENAME}" href="{U_FEED}" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_NEWS --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {L_FEED_NEWS}" href="{U_FEED}?mode=news" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_FORUMS --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {L_ALL_FORUMS}" href="{U_FEED}?mode=forums" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_TOPICS --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {L_FEED_TOPICS_NEW}" href="{U_FEED}?mode=topics" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_TOPICS_ACTIVE --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {L_FEED_TOPICS_ACTIVE}" href="{U_FEED}?mode=topics_active" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_FORUM and S_FORUM_ID --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {L_FORUM} - {FORUM_NAME}" href="{U_FEED}?f={S_FORUM_ID}" /><!-- ENDIF --> <!-- IF S_ENABLE_FEEDS_TOPIC and S_TOPIC_ID --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {L_TOPIC} - {TOPIC_TITLE}" href="{U_FEED}?f={S_FORUM_ID}&t={S_TOPIC_ID}" /><!-- ENDIF --> <!-- ENDIF --><!-- IF U_CANONICAL --> <link rel="canonical" href="{U_CANONICAL}" /> <!-- ENDIF --><!-- phpBB style name: prosilver Based on style: prosilver (this is the default phpBB3 style) Original author: Tom Beddard ( http://www.subBlue.com/ ) Modified by: --><link href="{T_THEME_PATH}/print.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet" type="text/css" media="print" title="printonly" /> <!-- IF S_ALLOW_CDN --><link href="//fonts.googleapis.com/css?family=Open+Sans:600&subset=latin,cyrillic-ext,latin-ext,cyrillic,greek-ext,greek,vietnamese" rel="stylesheet" type="text/css" media="screen, projection" /><!-- ENDIF --> <link href="{T_STYLESHEET_LINK}" rel="stylesheet" type="text/css" media="screen, projection" /> <link href="{T_STYLESHEET_LANG_LINK}" rel="stylesheet" type="text/css" media="screen, projection" /> <link href="{T_THEME_PATH}/responsive.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet" type="text/css" media="only screen and (max-width: 700px), only screen and (max-device-width: 700px)" /><!-- IF S_CONTENT_DIRECTION eq 'rtl' --> <link href="{T_THEME_PATH}/bidi.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet" type="text/css" media="screen, projection" /> <!-- ENDIF --><!-- IF S_PLUPLOAD --> <link href="{T_THEME_PATH}/plupload.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet" type="text/css" media="screen, projection" /> <!-- ENDIF --><!--[if lte IE 9]> <link href="{T_THEME_PATH}/tweaks.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet" type="text/css" media="screen, projection" /> <![endif]--><!-- EVENT overall_header_head_append -->{$STYLESHEETS} <!-- EVENT overall_header_stylesheets_after --> <script type="text/javascript"> var _mfq = _mfq || []; (function () { var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true; mf.src = "//cdn.mouseflow.com/projects/b22343cd9-0049-4443-8326-954444462d6515.js"; document.getElementsByTagName("head")[0].appendChild(mf); })(); </script> </head> <body id="phpbb" class="nojs notouch section-{SCRIPT_NAME} {S_CONTENT_DIRECTION} {BODY_CLASS}"><!-- EVENT overall_header_body_before --><div id="wrap"> <a id="top" class="anchor" accesskey="t"></a> <div id="page-header"> <div class="headerbar"> <div class="inner"> <div id="site-description"> <a id="logo" class="logo" href="<!-- IF U_SITE_HOME -->{U_SITE_HOME}<!-- ELSE -->{U_INDEX}<!-- ENDIF -->" title="<!-- IF U_SITE_HOME -->{L_SITE_HOME}<!-- ELSE -->{L_INDEX}<!-- ENDIF -->">{SITE_LOGO_IMG}</a> <h1>{SITENAME}</h1> <p>{SITE_DESCRIPTION}</p> <p class="skiplink"><a href="#start_here">{L_SKIP}</a></p> </div> <!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH --> <div id="search-box" class="search-box search-header"> <form action="{U_SEARCH}" method="get" id="search"> <fieldset> <input name="keywords" id="keywords" type="search" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search tiny" size="20" value="{SEARCH_WORDS}" placeholder="{L_SEARCH_MINI}" /> <button class="button icon-button search-icon" type="submit" title="{L_SEARCH}">{L_SEARCH}</button> <a href="{U_SEARCH}" class="button icon-button search-adv-icon" title="{L_SEARCH_ADV}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS} </fieldset> </form> </div> <!-- ENDIF --> </div> </div> <!-- INCLUDE navbar_header.html --> </div><!-- EVENT overall_header_page_body_before --><a id="start_here" class="anchor"></a> <div id="page-body"> <!-- IF S_BOARD_DISABLED and S_USER_LOGGED_IN and (U_MCP or U_ACP) --> <div id="information" class="rules"> <div class="inner"> <strong>{L_INFORMATION}{L_COLON}</strong> {L_BOARD_DISABLED} </div> </div> <!-- ENDIF --> <!-- EVENT overall_header_content_before -->
×
×
  • 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.