barryd

PHP Complete Install/Initial functions/classes/ext

Jun 10th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.88 KB | None | 0 0
  1. http://www.webdevout.net/articles/escaping-style-and-script-data
  2.  
  3. Required / Prerequisite
  4.  
  5. 7-zip (http://www.7-zip.org/download.html)
  6. Opening zip files with 7-zip (zip/tar/exe/7z/gz)
  7. "C:\Program Files (x86)\7-Zip\7zFM.exe"
  8.  
  9. GnuWin32 Tools (http://gnuwin32.sourceforge.net/packages/gzip.htm)
  10. (http://gnuwin32.sourceforge.net/packages/bzip2.htm)mv /path/to/file/A.current /path/to/file/A.backup
  11. Opening build sources and compress/uncompress w/ phpMyAdmin MySQL (gz/tar/tgz)
  12.  
  13. C:\Program Files (x86)\GnuWin32\bin
  14. bzip2.exe
  15. gzip.exe
  16.  
  17.  
  18. Environment Variables
  19.  
  20. My Computer (Right-Click)
  21. -> Properties (Control Panel\All Control Panel Items\System)
  22. -> Advanced System Settings (> Windows 7 (Left hand menu))
  23. -> System Properties
  24. -> Advanced
  25. -> Environment Variables...
  26. -> System variables
  27. -> Path
  28.  
  29. Variable: Path (system specific...)
  30. Value: C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Apache2\bin\;C:\php\;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files (x86)\SMplayer\mplayer\;
  31.  
  32.  
  33. Run CMD.exe as Administrator "Desktop Shortcut"
  34.  
  35. Right-Click on the Desktop > New Shortcut
  36. cmd | cmd.exe
  37.  
  38. Start -> Run
  39. cmd | cmd.exe
  40.  
  41.  
  42. PHP 5.4.8 (http://windows.php.net/download/#php-5.4)
  43.  
  44. Install with default settings by copying the files from the latest zip
  45.  
  46. +Installing as a modual for Apache2.2, you need -- VC9 x86 Thread Safe (zip)
  47.  
  48. http://windows.php.net/downloads/releases/php-5.4.8-Win32-VC9-x86.zip (Threaded)
  49. comes with - C:\php\php5apache2_2.dll is mentioned later on and loaded with Apache2.2
  50.  
  51. copy C:\php\php.ini-production php.ini
  52.  
  53. notepad C:\php\php.ini
  54.  
  55. extension_dir="C:/php/ext/"
  56.  
  57. Line 883:
  58. ;extension=php_mysqli.dll
  59. >> extension=php_mysqli.dll
  60.  
  61. C:\Users\Dulcie\Downloads\php_http-5.3-svn20091125-vc6-x86.zip
  62.  
  63. copy /b test.php +,,
  64. notepad test.php
  65. <?php echo 'hello world.'; ?>
  66.  
  67. php test.php Result: hello world.
  68.  
  69. $var = 'hello world;'
  70.  
  71. echo '\'0\'' . ' does not show variables $var'; //Result: 0 does not show variables $var
  72. echo "\'1\'" . " does show variables $var"; //Result: 1 does show variables hello world
  73.  
  74. ------------------------------------------------------------
  75. PHP 5.5 is in beta (2012-03-21)
  76.  
  77. http://downloads.php.net/pierre/
  78.  
  79.  
  80. PhpMyAdmin (http://www.phpmyadmin.net/home_page/downloads.php) [english]
  81.  
  82. cd C:\Apache2\htdocs\phpMyAdmin\
  83.  
  84. mdkir config
  85.  
  86. http://localhost/phpymadmin/setup/index.php
  87.  
  88. Create a server profile
  89. localhost...defaults...
  90.  
  91.  
  92. Apache 2.2 (http://httpd.apache.org/download.cgi)
  93.  
  94. notepad C:\Apache2\conf\httpd.conf (change)
  95.  
  96. Listen 80
  97. >> Listen 127.0.0.1:80 (change to only allow from localhost/127.0.0.1:80)
  98.  
  99. LoadModule php5_module "c:/php/php5apache2_2.dll"
  100. AddHandler application/x-httpd-php .php
  101.  
  102. # configure the path to php.ini
  103. PHPIniDir "C:/php"
  104.  
  105. <FilesMatch \.php$>
  106. SetHandler application/x-httpd-php
  107. </FilesMatch>
  108.  
  109. Line 252: DirectoryIndex index.html index.php
  110.  
  111.  
  112. .htaccess (File)
  113.  
  114. When operating php from the command prompt, remember to be cautious for extended lines suddenly breaks on with spaces. Default: If the line exceeds 80 characters, it could have a space between it and the line below, if the character ending the initial line is a space then your pretty safe. With out being cautious, you could by with a backspace/delete and accidently remove or forget to add the appropriate space.
  115.  
  116. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
  117.  
  118. http://www.javascriptkit.com/howto/htaccess2.shtml
  119.  
  120. (.htaccess)
  121.  
  122. chmod 644 php.ini
  123.  
  124. ErrorDocument 400 /.http/400.shtml
  125. ErrorDocument 401 /.http/401.shtml
  126. ErrorDocument 403 /.http/403.shtml
  127. ErrorDocument 404 /.http/404.shtml
  128. ErrorDocument 500 /.http/500.shtml
  129.  
  130. <!-- SHTML Wrapper - 500 Server Error -->
  131. <!--#exec cgi="/500.php" -->
  132.  
  133. Options -Indexes
  134. PHP_Value //in the .htaccess
  135.  
  136. RewriteEngine On
  137. RewriteCond %{HTTP_HOST} ^fbcgf\.ca
  138. RewriteCond %{HTTPS} =on
  139. RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]
  140. RewriteCond %{HTTP_HOST} ^fbcgf\.ca
  141. RewriteCond %{HTTPS} !=on
  142. RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]
  143.  
  144. RewriteBase /b33m
  145. RewriteRule ^blogs/([0-9]+)$ /view_blog_details.php?post_id=$1 [L]
  146.  
  147. Options +FollowSymlinks
  148. RewriteEngine on
  149. RewriteRule ^abate /abatepain.com/public_html/abate/ [L]
  150.  
  151.  
  152. RewriteEngine on
  153. RewriteCond %{REQUEST_URI} ^/$
  154. RewriteRule (.*) http://www.abatepain.com/abate/ [R=301,L]
  155.  
  156.  
  157.  
  158. <IfModule dir_module>
  159. DirectoryIndex default.html index.php home.php
  160. </IfModule>
  161.  
  162. <Files notes.txt>
  163. order deny,allow
  164. deny from all
  165. </Files>
  166.  
  167. Services install Service
  168.  
  169. Apache 2.2 automatically is applied/added to the services on a default installation. Once restarted!
  170.  
  171. Windows 7+
  172. Control Panel\All Control Panel Items\Administrative Tools\services.lnk
  173. >>C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\services.lnk
  174. %windir%\system32\services.msc
  175.  
  176. Add a regular firewall filter to allow port 80, and restart apache2.2 service.
  177.  
  178. Windows XP
  179. %windir%\system32\services.msc
  180.  
  181. C:\Apache2\bin\httpd.exe -k install
  182.  
  183. C:\Apache2\bin\httpd.exe -k start / stop
  184.  
  185.  
  186. HTTP GET
  187.  
  188. PHP
  189. Request URL (http://localhost/helloworld.php)
  190.  
  191. Request URI (/helloworld.php?...)
  192.  
  193. When checking to see if a GET values are not set (null), don't use ( is_null() ) :
  194.  
  195. http://davidwalsh.name/php-ternary-examples
  196. Use:
  197. !empty() Ternary Condition echo 'Is setup ready? ' . (!empty($_GET['setup']) ? true : false);
  198.  
  199.  
  200. Raw Socket connect to make basic request. (\n = new line)
  201.  
  202. CMD > telnet localhost 80
  203.  
  204. GET /helloworld.php?string=value&bstring=bvalue&cstring=cvalue HTTP/1.1\n
  205. \n
  206. --------------
  207.  
  208. //$_GET is now populated with 3 values (array)
  209.  
  210. print_r($_GET); // returns mentioned below.
  211.  
  212. Array { 'string' => 'value', bstring => 'bvalue', cstring => 'cvalue' }
  213.  
  214.  
  215.  
  216. HTTP POST
  217.  
  218. When checking to see if a GET values are not set (null), don't use ( is_null() ) :
  219.  
  220. Use:
  221. !empty() Ternary Condition echo 'Is setup ready? ' . (!empty($_POST['setup']) ? true : false);
  222.  
  223. Raw Socket connect to make basic request. (\n = new line)
  224.  
  225. CMD > telnet localhost 80
  226.  
  227. POST /path/script.cgi HTTP/1.0
  228. From: frog@jmarshall.com
  229. User-Agent: HTTPTool/1.0
  230. Content-Type: application/x-www-form-urlencoded
  231. Content-Length: 32
  232.  
  233. home=Cosby&favorite+flavor=flies\n
  234. ------------------
  235.  
  236. //$_POST is now populated with 3 values (array)
  237.  
  238. print_r($_POST); // returns mentioned below.
  239.  
  240. Array { 'home' => 'Cosby', 'favorite+flavor' => 'flies' }
  241.  
  242.  
  243. MySQL Server 5.5 (http://www.mysql.com/downloads/installer/)
  244.  
  245. Install with default settings.
  246.  
  247. Services install Service
  248.  
  249.  
  250.  
  251. Table Maintenance Statements (13.7.2)
  252.  
  253. ANALYZE TABLE Syntax (13.7.2.1)
  254. ANALYZE TABLE `session`
  255.  
  256. BACKUP TABLE Syntax (13.7.2.2)
  257. BACKUP TABLE `table`
  258.  
  259. CHECK TABLE Syntax (13.7.2.3)
  260. CHECK TABLE `session` (, `table2`... ) EXTENDED ( QUICK | FAST | CHANGED | MEDIUM | EXTENDED )
  261. QUICK Do not scan the rows to check for incorrect links. Applies to InnoDB and MyISAM tables and views.
  262. FAST Check only tables that have not been closed properly. Applies only to MyISAM tables and views; ignored for InnoDB.
  263. CHANGED Check only tables that have been changed since the last check or that have not been closed properly. Applies only to MyISAM tables and views; ignored for InnoDB.
  264. MEDIUM Scan rows to verify that deleted links are valid. This also calculates a key checksum for the rows and verifies this with a calculated checksum for the keys. Applies only to MyISAM tables and views; ignored for InnoDB.
  265. EXTENDED Do a full key lookup for all keys for each row. This ensures that the table is 100% consistent, but takes a long time. Applies only to MyISAM tables and views; ignored for InnoDB.
  266.  
  267. CHECKSUM TABLE Syntax (13.7.2.4)
  268. OPTIMIZE TABLE Syntax (13.7.2.5)
  269.  
  270. REPAIR TABLE Syntax (13.7.2.6)
  271. REPAIR TABLE `session` [QUICK] [EXTENDED] [USE_FRM]
  272.  
  273. RESTORE TABLE Syntax (13.7.2.7)
  274.  
  275.  
  276. SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO';
  277.  
  278. ALTER TABLE `table_name` AUTO_INCREMENT = 1
  279.  
  280. RENAME TABLE `db_name`.`table_name` TO `db_name`.`table_name` ;
  281.  
  282. ALTER TABLE `db_name`.`table_name` ADD PRIMARY KEY ( `id` )
  283.  
  284. ALTER TABLE `db_name` ADD `tbl_name` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
  285.  
  286.  
  287. ALTER TABLE `patient_session` CHANGE `ipaddr` `ipaddr` VARCHAR( 15 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '0.0.0.0'
  288.  
  289. UPDATE `db_name`.`table_name` SET `timestamp` = '0000-00-00 00:00:00' WHERE `table_name`.`id` =0;
  290.  
  291.  
  292. SELECT timestamp FROM tablename WHERE timestamp >= STR_TO_DATE('" . date('m/d/Y' , strtotime( '-1 hour', $_SESSION['LAST_ACTIVITY'])) . "', '%m/%d/%Y') AND timestamp < STR_TO_DATE('" . date('m/d/Y' , strtotime( '-1 hour', time())) . "', '%m/%d/%Y');
  293.  
  294. SELECT timestamp from `account_session` WHERE timestamp >= "01-01-2009 00:00:00" and datetime <= now();
  295.  
  296. SELECT timestamp FROM `account_session` WHERE timestamp >= userStartDate AND timestamp < userEndDate
  297.  
  298. SELECT timestamp FROM `account_session` WHERE `timestamp` >= UNIX_TIMESTAMP('') AND `timestamp` <= UNIX_TIMESTAMP('')
  299.  
  300. http://www.c-integration.com/forum/showthread.php/56-rapid-web-application-using-qcubed
  301.  
  302. CREATE TABLE `comment` (
  303. `id` int(11) NOT NULL AUTO_INCREMENT,
  304. `post_id` int(11) NOT NULL,
  305. `comment_body` varchar(1000) NOT NULL,
  306. PRIMARY KEY (`id`),
  307. KEY `post_id` (`post_id`)
  308. ) ENGINE=InnoDB;
  309.  
  310. CREATE TABLE `post` (
  311. `id` int(11) NOT NULL AUTO_INCREMENT,
  312. `title` varchar(128) NOT NULL,
  313. `body` varchar(10000) NOT NULL,
  314. PRIMARY KEY (`id`)
  315. ) ENGINE=InnoDB;
  316.  
  317. ALTER TABLE `comment`
  318. ADD CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `post` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
  319.  
  320.  
  321. CURRENT_TIMESTAMP does not have quotes / escape
  322. NULL does not have quotes / escape
  323.  
  324. blob can have a 0 byte string w/o having to use null / default
  325.  
  326.  
  327. '\'\''
  328.  
  329. '\'\'' . ', ' .
  330.  
  331. -----------------------------------------------------------
  332. PHP 5.4 (file.php)
  333.  
  334.  
  335.  
  336. if (isset($_GET['src'])) {
  337.  
  338. highlight_file('index.php'); //__FILE__
  339.  
  340. die();
  341.  
  342. }
  343.  
  344. http://www.creotec.com/php-web-development/
  345.  
  346.  
  347. <?php
  348.  
  349. /** Error reporting */
  350.  
  351. ini_set("log_errors", 1);
  352. ini_set("error_log", "/path/to/php-error.log");
  353.  
  354. error_reporting(E_ALL);
  355.  
  356.  
  357. /** Include path **/
  358. ini_set('include_path', ini_get('include_path').';../Classes/');
  359.  
  360. //include('include.php');
  361. require_once(dirname(__FILE__) . '/include.php');
  362.  
  363. ?>
  364.  
  365. error_log
  366.  
  367. Will always spit out php errors / dates/time and its corrsponding file / line.
  368.  
  369. [01-Jan-1970 12:01:36] PHP Fatal error: Cannot redeclare functionName() (previously declared in /home/parentDirectory/www_dir/public_html/index.php:32) in /home/parentDirectory/www_dir/public_html/include.php on line 37
  370.  
  371.  
  372. include() // Suggested replacment require_once()
  373.  
  374.  
  375. /directory/to/htdocs/phpfiles/
  376.  
  377. index.php
  378. <?php require_once(dirname(__FILE__) . '/include.php'); ?>
  379.  
  380. include.php
  381.  
  382. http://www.expertrating.com/courseware/PHPcourse/PHP-Advanced-ClassConcepts-11-2.asp
  383.  
  384. index.php
  385. __FILE__ == /directory/to/htdocs/phpfiles/index.php
  386.  
  387. http://www.domain.com/phpfiles/index.php?hello
  388. $_SERVER['PHP_SELF'] == '/phpfiles/index.php'
  389.  
  390. if (key($_GET)) {
  391. switch (key($_GET)) {
  392. /* case '': $null = NULL; break; */
  393. case 'hello':
  394. echo 'hello world from index.php';
  395. break;
  396. }
  397. }
  398.  
  399. Result: hello world from include.php
  400. Unless there is an included file mentioned above the condition ( if (key($_GET)) { ... )
  401.  
  402. include('include.php');
  403.  
  404. include.php
  405. __FILE__ == /directory/to/htdocs/phpfiles/include.php
  406.  
  407. http://www.domain.com/phpfiles/index.php (if included)
  408. $_SERVER['PHP_SELF'] == '/phpfiles/index.php'
  409. (else)
  410. $_SERVER['PHP_SELF'] == '/phpfiles/include.php'
  411.  
  412. if (key($_GET)) {
  413. switch (key($_GET)) {
  414. /* case '': $null = NULL; break; */
  415. case 'hello':
  416. echo 'hello world from include.php';
  417. break;
  418. }
  419. }
  420.  
  421. Result: hello world from include.php
  422.  
  423.  
  424. if(!@include("script.php")) throw new Exception("Failed to include 'script.php'");
  425.  
  426.  
  427. /*
  428. if (in_array(__FILE__, get_included_files()) === false) {
  429. header('Location: http://www.domain.com/');
  430. die();
  431. }
  432.  
  433.  
  434. /*
  435. if (array_search(__FILE__, get_included_files()) === false) {
  436. header('Location: http://www.domain.com/');
  437. }
  438. else {
  439. require_once(dirname(__FILE__) . '/include.php');
  440.  
  441. echo __FILE__;
  442. }
  443. */
  444.  
  445.  
  446. $_SESSION[]
  447.  
  448. ini_set("session.entropy_file", "/dev/urandom");
  449. ini_set("session.entropy_length", "512");
  450.  
  451.  
  452. if (!isset($_SESSION)) { session_start(); }
  453.  
  454. if (empty($_SESSION['CREATED']) || empty($_SESSION['LAST_ACTIVITY'])) {
  455. $_SESSION['CREATED'] = time();
  456. $_SESSION['LAST_ACTIVITY'] = time();
  457. } else { $_SESSION['LAST_ACTIVITY'] = time(); }
  458.  
  459. if (time() - $_SESSION['CREATED'] > 450 ) {
  460. // last request was more than 30 minates ago (1800)
  461. $_SESSION = array();
  462. session_destroy(); // destroy session data in storage
  463. session_unset(); // unset $_SESSION variable for the runtime
  464. header('Location: http://www.domain.com/');
  465. } elseif ($_SESSION['LAST_ACTIVITY'] - $_SESSION['CREATED']> 180) {
  466. session_regenerate_id(true); // change session ID for the current session an invalidate old session ID
  467. $_SESSION['CREATED'] = time();
  468. }
  469.  
  470.  
  471. Date / Time
  472.  
  473. date_default_timezone_set('America/Vancouver');
  474.  
  475. date('Y-m-d H:i:s', strtotime( '-1 hour', time())); datetime
  476.  
  477. strtotime('-1 hour', time()) //time() - (60 * 60); // 60 x 60 (secs x secs) 1 hour
  478.  
  479. time(); //UNIX Timestamp since 1970
  480.  
  481. if ($_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'] == __FILE__ ){
  482. header('Location: http://www.domain.com/');
  483. die();
  484. }
  485. If you are choosing to include a file from a subdirectory, and you still want to use relative links, instead of absolute (site-relative...), then you must set the HTML base tag in the head, in order for the browser to know where the src's and links are ... <base href="http://www.domain.com/absolute/location/of/parent/directory" />
  486.  
  487. --PHP will always include files parent files, and absolute/relative, so you do not need to worry about adjusting the variables.
  488.  
  489. Use absolute file location (__FILE__) when including files, that way you don't have to worry about relative links.
  490.  
  491.  
  492. //comment (single line)
  493.  
  494. Does not work with 1-line php script as php is still assuming that comment is still there, even though its reached the end.
  495. <?php //testing ?>
  496.  
  497. /* comment */ (single / multiple lines)
  498.  
  499. Does however fix both these issues, and is there more efficient.
  500. <?php /*Comment*/ ?>
  501.  
  502. $variable = ''; //===is_null($variable) ===empty($variable) !==isset($variable) !==$variable ===NULL ===false!
  503. $variable = '0'; //!==is_null() !==empty() ===isset ===$variable !==NULL ===true
  504.  
  505. $_POST['test1'] === NULL !isset()
  506.  
  507. $x = NULL;
  508.  
  509. if(is_null($x) === true) // null
  510. if($x === null) // null
  511. if($x === false)
  512. if(isset($x) === false) // variable undefined or null
  513. if(empty($x) === true) // check if variable is empty (length of 0)
  514.  
  515. $array = array(); //===empty
  516.  
  517. $array['key'] = 'value';
  518. $array[0] = "is not restrictive to a particular rule";
  519. $array['just as long as your code ie constructive'] = 'your script won\'t become destructive.';
  520. $array['1'] = 'You just need to realize the escape rules with ' . 'php.' . " You can you use lots of syntax methods including conditional (if / else) statments and functions() " . "from within the variable definition. " . ((1===1) ? ' This should return (true)' : "I guess not (false).");
  521. $array["\"2\""] = 'These are just a few of the numerous reasons why ' . 'php is soo cool to play with...';
  522. $array[3] = array();
  523. $array[4] = 'Array values can also be defined as objects ... as to have an "array of objects"';
  524.  
  525. print_r($array);
  526. /*
  527. Returns:
  528. Array
  529. (
  530. [key] => value
  531. [0] => is not restrictive to a particular rule
  532. [just as long as your code ie constructive] => your script won't become destructive.
  533. [1] => You just need to realize the escape rules with php. You can you use lots of syntax methods including conditional (if / else) statments and functions() from within the variable definition. This should return (true)
  534. ["2"] => These are just a few of the numerous reasons why php is soo cool to play with...
  535. [3] => Array
  536. (
  537. )
  538.  
  539. [4] => Array values can also be defined as objects ... as to have an "array of objects"
  540. )
  541.  
  542. */
  543.  
  544. PHP MySQL (ext/mysql) Deprecated 5.5/6.0
  545.  
  546. Works in 5.4 still (pdo_mysql or MySQLi prefered alternitives)
  547.  
  548.  
  549. mysqli_query($link, $query);
  550.  
  551. mysqli_insert_id()
  552.  
  553. LAST_INSERT_ID()
  554.  
  555. if(!$res = mysql_query("SELECT * FROM `session_active` WHERE `session` =" . $session_id . ';', $myconnect)) { die("ERROR: " . mysql_error()); }
  556.  
  557. $row = mysql_fetch_assoc($res);
  558.  
  559.  
  560. foreach ($){
  561. $row = mysql_fetch_assoc(mysql_query("SELECT * FROM `takenote`.`timesheet` WHERE `timestamp` = '" . date('Y-m-d', strtotime($gdate)) . ' ' . $schedule . "' LIMIT 0 , 30", $myconnect));
  562. }
  563.  
  564.  
  565. while($row = mysql_fetch_array($result)) {}
  566.  
  567.  
  568. --------------------------------------------------------------
  569. HTML / XHTML (file.html)
  570.  
  571. Document-relative links ../../folder/file.ext
  572.  
  573. Site Root Relative /root/folder/file.ext
  574.  
  575.  
  576. (X)HTML
  577.  
  578. <base href="http://www.domain.com/abate/">
  579.  
  580. Does not affect <link />
  581. But does however affect <script />
  582.  
  583. XHTML
  584.  
  585. <base href="http://www.domain.com/abate/" />
  586.  
  587. <script type="text/javascript">
  588. //<![CDATA[
  589.  
  590. //]]>
  591. </script>
Add Comment
Please, Sign In to add comment