Web Development

  • How to avoid web content hijacking/copying/Force content to be accessed by only 1 domain name


    This is something that happens a lot and it is very dirty, as you probably know each site is hosted on a certain IP address. Sometimes a domain is hosted by a single IP address and the IP address defaults to this very same domain. This means that if someone buys domain abcd.com and enters your IP address (the one of your website) as the A record, your content will show up on their domain as if it was their own. There is an easy way to prevent this by using .htaccess, these 2 lines of code simply tell Apache that if your content is being accessed by anything other than yourrealdomain.com to redirect to "yourrealdomain.com": RewriteCond %{HTTP_HOST} !^yourrealdomain.com RewriteRule ^(.*) http://yourrealdomain.com/$1 [R=permanent,L] This will prevent sites from hijacking your content. Iknow people say Google can detect duplicate content and which site was the original one, but I don't believe this. A domain that hijacked one of my sites started getting our content indexed under the domain name they used to hijack my content. This is something that you should put in the .htaccess of every site you have to prevent this, it also has the benefit of eliminating difference links pointing to the www. version of your site, this forces everything to your root domain.
  • Process/Parse PHP from HTML files using .htaccess and allowoverride


    RemoveHandler .html .htmAddType application/x-httpd-php .php .htm .html Just add the above into the .htaccess file for your website. Also remember that you need to be allowed to override the Apache and this should go into the vhost for your site as shown below: # you need the AllowOverride otherwise .htaccess directives will be ignoredOptions FollowSymLinksAllowOverride All
  • Enable/Disable PHP Warnings/Logs and Errors from .htaccess with Apache


    Put what you see below into your .htaccessand it will enable errors and notices. (change on to off and 1 to 0 to disable though) php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on Now you'll be able to see errors and notices but this should really only be used for debugging purposes and only temporarily as it can be a security issue since errors can reveal information you wouldn't want hackers to know about.
  • JavaScript get valued of selected <select> drop down l


    JavaScript get valued of selected drop down l [code:1:4be190f44a]Package = OrderForm.package.options[OrderForm.package.selectedIndex].value;[/code:1:4be190f44a] OrderForm = Name of HTML form the SELECT is inside package = Name of SELECT element eg. JavaScript says form name is not defined even though it is I've integrated this into my design and I got an error saying the Form Name is not defined, even though in a standalone page the same code with the same form name which is defined is there. Here is what normally worked: [code:1:f5ffccc1a6] Package = OrderForm.package.options[OrderForm.package.selectedIndex].value;[/code:1:f5ffccc1a6] I also tried: [code:1:f5ffccc1a6] Package = [b]document[/b].OrderForm.package.options[OrderForm.package.selectedIndex].value;[/code:1:f5ffccc1a6] Ok this is messed up........llike I said the code worked fine before, but not with the integration of my site. The whole thing came down to the doctype! I have no idea why but here is the bad DOCTYPE: [code:1:f5ffccc1a6] [/code:1:f5ffccc1a6] Good DOCTYPE [code:1:f5ffccc1a6] [/code:1:f5ffccc1a6]
  • JavasScript how to set or write value in id tag


    JavasScript how to set or write value in id tagbla I need to set a value inside that DIV tag using Javascript, how would I do it?Doesn't work for me: [quote:c6b5f693a5]Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead. Source File: http://hosting.com/vps-order.html Line: 19[/quote:c6b5f693a5] [code:1:c6b5f693a5] function WriteDIVText() { document.getElementById("DIVText").innerText = "Here is replacement text for the division."; } Here is a division containing text. [/code:1:c6b5f693a5]use "innerHTML" instead and it will work [code:1:13693b649f] document.getElementById("displaytheprice").innerHTML = "wheeeeeeeeeeeeeeeeee";[/code:1:13693b649f]
  • PHP CURL SSL won't work or connect


    I spent so much time debugging this, most sites don't tell you a very important option to use with CURL and you will only find out this is the problem by running the PHP script from the command line you get the following output that shows the issue (I don't see any way to get this output from Apache itself). * About to connect() to ip.ip.ip.ip port 25000 * Trying ip.ip.ip.ip... * connected * Connected to ip.ip.ip.ip (ip.ip.ip.ip) port 25000 * successfully set certificate verify locations: * CAfile: /usr/share/ssl/certs/ca-bundle.crt CApath: none * SSL connection using DHE-RSA-AES256-SHA * Server certificate: * subject: /C=--/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=domain.com/emailAddress=us@domain.com * start date: 2010-10-20 04:23:10 GMT * expire date: 2011-10-20 04:23:10 GMT * SSL: certificate subject name 'domain.com' does not match target host name 'ip.ip.ip.ip' * Closing connection #0 Content-type: text/html X-Powered-By: PHP/4.3.9 The solution Add the following to your CURL options: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false); The VERIFYHOST option is what I was missing.
  • PHP Email Attachment Corrupt Solution


    I couldn't figure out why this wouldn't work, a test script in the root of my htdocs folder worked fine. Within some subdirectories the same code would produce different base64 results but I didn't know hwy. Archive: /tmp/archive.zip Zip file size: 6888 bytes, number of entries: 92 error [/tmp/archive.zip]: missing 242827681 bytes in zipfile (attempting to process anyway) error [/tmp/archive.zip]: attempt to seek before beginning of zipfile (please check that you have transferred or created the zipfile in the appropriate BINARY mode and that you have compiled UnZip properly) Here was the problem in .htaccess! It was because magic_quotes_gpc was being turned of by my htaccess within the subdirectory. Now after disabling it the e-mail attachment zip is not corrupt and works fine but it was a big headache and definitely required a lot of digging/headscratching. #php_flag magic_quotes_gpc off #php_flag magic_quotes_runtime on *Update It turns out that the real issue was just the "magic_quotes_runtime" being on. It still works fine with the magic_quotes_gpc being turned off.
  • PHP Fatal error: Call to undefined function mysql_connect()


    PHP Fatal error: Call to undefined function mysql_connect() yum install php-*
  • PHP Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file


    I was having an issue with only certain random/jpeg files with the functions imagecreatefromjpeg imagecreatetruecolor and other related ones. This issue was annoying basically it seems like a libgd issue/bug with newer versions of PHP and it was difficult to trace-out. One very useful thing that helped me was using "php-cgi" and passing the query string as an argument eg: php-cgi images.php source=IMG.jpg (that way you get all the error messages which lead me to below): PHP Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file The solution is to tweak the PHPGD settings to ignore this warning /etc/php.ini [gd] ; Tell the jpeg decode to ignore warnings and try to create ; a gd image. The warning will then be displayed as notices ; disabled by default ; http://www.php.net/manual/en/image.configuration.php#ini.image.jpeg-ignore-warning gd.jpeg_ignore_warning = 1
  • PayPal subscriptions automatically cancelling after creation of profile


    There is a weird quirk with how this works, but there is a variable called "src" that defaults to 0 or disabled if not specified as 1. The default 0 means not to recur billing on a subscription.  It's too bad it's not more obvious anywhere nor is there an explanation or warning during payment or after to both the seller and buyer. Here's a proper subscription code example that does recur and does not cancel: Note the following a3= the recurring value p3= the period it recurs on t3 = the period timeframe (eg M for month or Y for year etc..) <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="your-business-seller-id"> <input type="hidden" name="a3" value="19.99"> <input type="hidden" name="p3" value="3"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name" value="Item Name"> <input type="hidden" name="amount" value="19.99"> <input type="hidden" name="src" value="1"> <input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> form>
  • The redirect URI in the request: urn:ietf:wg:oauth:2.0:oob can only be used by a Client ID for native application. It is not allowed for the 'WEB' client type.


    You need to set your application type as "Desktop" even though this would sound counterintuitive.
  • Error code: ssl_error_rx_record_too_long


    An error occurred during a connection to site.com. SSL received a record that exceeded the maximum permissible length. (Error code: ssl_error_rx_record_too_long) The page you are trying to view cannot be shown because the authenticity of the received data could not be verified. Please contact the website owners to inform them of this problem. When the above happens in our experience it is a misconfiguration of your web server, in our case usually it would be Apache and the port you are connecting to is meant for non-SSL.
  • Force SSL for all URLs Apache htaccess modrewrite


    The best way is as below in .htaccess using modrewrite, any request that is not SSL will be redirected to https://domain.com and the exact same URL RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
  • Redirect www host to non-www Linux Apache modrewrite


    The below forces all request to your domain to go to the main non-www root domain. Updated code: RewriteCond %{HTTP_HOST} !=domain.com RewriteRule ^(.*)$ https://newurl.com/subdir/$1 [R=301,L] If you don't want it to go to a subdirectory: RewriteCond %{HTTP_HOST} !=domain.com RewriteRule ^(.*)$ https://newurl.com/$1 [R=301,L] Bad code: This code is bad because the REQUEST_URI is not valid or correct if you want to rewrite to a subdirectory and may cause a // home page etc... RewriteCond %{HTTP_HOST} !=domain.com RewriteCond %{HTTP_HOST} !="" RewriteRule ^ http://domain.com/%{REQUEST_URI} [R=301,L]
  • css .ul and .li how to remove the identation padding/margin from list items?


    A common mistake is people think you should tell the li padding to be 0px but this is wrong. All you need is the following code in line: your item your item In a css class: .yourclass { ul.margin: 0px; }
  • "Object of class WP_Term could not be converted to string"


    Normally when I've seen this it's when you are using a variable like a normal string when in fact it's actually an array such as this example: [Tue Mar 13 04:22:35 2018] [error] PHP Catchable fatal error: Object of class WP_Term could not be converted to string in /vhost/httpdocs/wp-content/plugins/wp-instagram-post/classes/class-woo-igp.php on line 578 $tags = get_tags($post_id); foreach ( $tags as $tag ) { $the_tags=$the_tags. "#". $tag; } With the above the $tag variable actually is an array so you would need to reference it like this $tag->name or $tag["name"];
  • PHP Issues With Decoding Strange Smart Quotes And Non-Standard ASCII Characters


    When using strip_tags and html_entity_decode with PHPit often breaks and produces annoying diamonds with question marks. It is probably because of characters like these: … (looks like 3 dots but it is a single weird character). ’ (looks like a normal apostraphe but it is not) ” (looks like a normal double quote but it is not). An easy way to sort this out is to copy the above and search in an ASCII table to extend the functionality below. Basically the first array has a list of "all the bad stuff" and the second array is what to replace it with.
  • syntax error, unexpected T_SL in PHP Solution


    This happened in a PHPscript with heredoc but it could really happen anywhere. The issue was whitespace in code like this: $variable =
  • Latest Articles

  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm
  • docker swarm silly issues
  • isc-dhcp-server dhcpd how to get longer lease
  • nvidia cannot resume from sleep Comm: nvidia-sleep.sh Tainted: Linux Ubuntu Mint Debian
  • zfs and LUKS how to recover in Linux
  • [error] (28)No space left on device: Cannot create SSLMutex Apache Solution Linux CentOS Ubuntu Debian Mint
  • Save money on bandwidth by disabling reflective rpc queries in Linux CentOS RHEL Ubuntu Debian
  • How to access a disk with bad superblock Linux Ubuntu Debian Redhat CentOS ext3 ext4
  • ImageMagick error convert solution - convert-im6.q16: cache resources exhausted
  • PTY allocation request failed on channel 0 solution
  • docker error not supported as upperdir failed to start daemon: error initializing graphdriver: driver not supported
  • Migrated Linux Ubuntu Mint not starting services due to broken /var/run and dbus - Failed to connect to bus: No such file or directory solution
  • qemu-system-x86_64: Initialization of device ide-hd failed: Failed to get