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.   I know 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 .htm
    AddType 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 ignored
    <Directory "/www/vhosts/complaintdb.com/httpdocs">
    Options FollowSymLinks
    AllowOverride All
    </Directory>

  • 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 <select> 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.<select name="package">


    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]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    [/code:1:f5ffccc1a6]

    Good DOCTYPE

    [code:1:f5ffccc1a6] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">[/code:1:f5ffccc1a6]



  • JavasScript how to set or write value in id tag


    JavasScript how to set or write value in id tag

    <div id="price">bla</div>

    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]

    <script type="text/javascript">

    function WriteDIVText()
    {
    document.getElementById("DIVText").innerText =
    "Here is replacement text for the division.";
    }

    </script>

    <div id="DIVText" style="border:ridge 3px; padding:5px">
    Here is a division containing text.
    </div>

    <input type="button" value="Write to DIV" onclick="WriteDIVText()"/>[/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-*


  • Latest Articles

  • failed to IDENTIFY (INIT_DEV_PARAMS failed, err_mask=0x80)
  • pcnet32: eth0: transmit timed out, status 97fb, resetting - NIC card problem solution
  • Linux Screen How To Scroll Up and Down
  • Directadmin Install Segfault Error
  • Could not display "trash:///". Error: DBus error org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout
  • SSH error slow login debug1: An invalid name was supplied Cannot determine realm for numeric host address - Solution
  • How To Install CPanel
  • LOG: MAIN PANIC failed to expand condition "${if eq {$authenticated_id}{}{0}{${if eq {$sender_address}{$local_part@$domain}{0}{${if match{$received_protocol}{N^e?smtps?a$N}{${perl{checkbx_autowhitelist}{$authenticated_id}}}{${if eq{$received_prot
  • Firefox 11 closes/quits without saving Open Tabs Prompt Solution/Fix
  • Firefox 11 stop hiding http:// and https:// solution fix
  • The Importance of a High Quality Power Supply/Power Supplies To Prevent Overheating/System Crash/Hardware Damage
  • Asus VE247H 23.7" Inch LCD/LED Backlit Monitor Dead/Stuck Pixel Policy Complaint
  • Firefox Error ./firefox-bin: error while loading shared libraries: libxul.so: cannot open shared object file: No such file or directory
  • Linux Ubuntu Nvidia GT430 Lockups/Errors/Freezes NVRM: os_schedule: Attempted to yield the CPU while in atomic or interrupt context
  • Xen how to mount disk images off-line and access data
  • Xen non-HVM container won't work/boot anymore
  • how to exit xen console session from xm
  • Skype Linux/Ubuntu Sound Echo/Distortion Poor Quality Problem Fix Solution
  • Ubuntu 10.04 Flash Videos have tearing/lines Solution
  • File /etc/vz/conf/ve-vps.basic.conf-sample not found: No such file or directory - Openvz Error solution