Rectangle 27 2

The following is another solution using attributes() and children() only, tested and working OK! :)

$data=<<<XML

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
 <channel>
   <item>
    <title>Title: 0</title>
    <link test="test" test2="This is a test">Link:0</link>
    <media:thumbnail url="Thumbnail URL: 0"/>
    <media:content url="Content URL: 0" type="video/mp4" />
  </item>
    <item>
    <title>Title: 1</title>
    <link>Link:1</link>
    <media:thumbnail url="1"/>
    <media:content url="1" type="video/mp4" />
  </item>
 </channel>
</rss>

XML;



$xml=simplexml_load_string($data);

//reading simple node
echo $xml->channel[0]->item[0]->title;

echo "<br>----------------------------------<br>";

//reading/updating simple node's attribute
echo $xml->channel[0]->item[0]->link->attributes()->test2="This is a NEW test!.";

echo "<br>----------------------------------<br>";

//reading/updating namespaced node's attribute
echo $xml->channel[0]->item[0]->children('media',TRUE)->content->attributes()->type="VIDEO/MP6";

//saving...
$xml->asXml('updated.xml');

php - How to get attribute of node with namespace using SimpleXML? - S...

php xml namespaces simplexml
Rectangle 27 3

Use this .htaccess which is tested by me and working fine

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /CI/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule>

and in your config.php file use this,

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];

I have updated both the code and .htaccess. Now when I submit the form, I am receiving a "NetworkError: 500 Internal Server Error - 65.44.222.164/CI/login_ctrl/authenticateuserlogon instead of a 404 Not Found error

yes which means you got error in your code. please check your apache error logs

authenticateuserlogon

First, thanks for your patience because I am going crazy. :) Here are my apache error logs when for the 500 error [debug] mod_deflate.c(615): [client 98.154.88.186] Zlib: Compressed 1166 to 527 : URL /CI/index.php

[debug] mod_deflate.c(615): [client 98.154.88.186] Zlib: Compressed 1166 to 527 : URL /CI/index.php [debug] mod_deflate.c(615): [client 98.154.88.186] Zlib: Compressed 92651 to 32770 : URL /CI/js/jquery-1.9.1.min.js, referer: 65.44.222.164/CI [debug] mod_deflate.c(615): [client 98.154.88.186] Zlib: Compressed 3089 to 1061 : URL /CI/css/login.css, referer: 65.44.222.164/CI [debug] mod_deflate.c(615): [client 98.154.88.186] Zlib: Compressed 2638 to 1111 : URL /CI/js/login.js, referer: 65.44.222.164/CI

javascript - $.post to Codeigniter Controller/Method 404 Page Not Foun...

javascript php apache .htaccess codeigniter
Rectangle 27 63

I was having same problem with json_encode today. But after testing a lot I found the correct solution :

In php to encode the array or string:

PHP: json_encode(ARRAY, JSON_HEX_QUOT | JSON_HEX_TAG);
JS: var d = $.parseJSON(content);

I was having the same issue but I was almost to the solution. I was using json_encode($json, JSON_HEX_QUOT | JSON_HEX_APOS). Changing the JSON_HEX_APOS to JSON_HEX_TAG made my problems disappear!

This should be marked as the correct answer.

logged in just to upvote this

php - json_encode not working with a html string as value - Stack Over...

php jquery ajax json
Rectangle 27 63

I was having same problem with json_encode today. But after testing a lot I found the correct solution :

In php to encode the array or string:

PHP: json_encode(ARRAY, JSON_HEX_QUOT | JSON_HEX_TAG);
JS: var d = $.parseJSON(content);

I was having the same issue but I was almost to the solution. I was using json_encode($json, JSON_HEX_QUOT | JSON_HEX_APOS). Changing the JSON_HEX_APOS to JSON_HEX_TAG made my problems disappear!

This should be marked as the correct answer.

logged in just to upvote this

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - json_encode not working with a html string as value - Stack Over...

php jquery ajax json
Rectangle 27 62

I was having same problem with json_encode today. But after testing a lot I found the correct solution :

In php to encode the array or string:

PHP: json_encode(ARRAY, JSON_HEX_QUOT | JSON_HEX_TAG);
JS: var d = $.parseJSON(content);

I was having the same issue but I was almost to the solution. I was using json_encode($json, JSON_HEX_QUOT | JSON_HEX_APOS). Changing the JSON_HEX_APOS to JSON_HEX_TAG made my problems disappear!

This should be marked as the correct answer.

logged in just to upvote this

php - json_encode not working with a html string as value - Stack Over...

php jquery ajax json
Rectangle 27 14

Here's is some code I just wrote to handle the date formatting for a project I'm working on. It mimics the PHP date formatting functionality to suit my needs. Feel free to use it, it's just extending the already existing Date() object. This may not be the most elegant solution but it's working for my needs.

var d = new Date(); 
d_string = d.format("m/d/Y h:i:s");

/**************************************
 * Date class extension
 * 
 */
    // Provide month names
    Date.prototype.getMonthName = function(){
        var month_names = [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December'
                        ];

        return month_names[this.getMonth()];
    }

    // Provide month abbreviation
    Date.prototype.getMonthAbbr = function(){
        var month_abbrs = [
                            'Jan',
                            'Feb',
                            'Mar',
                            'Apr',
                            'May',
                            'Jun',
                            'Jul',
                            'Aug',
                            'Sep',
                            'Oct',
                            'Nov',
                            'Dec'
                        ];

        return month_abbrs[this.getMonth()];
    }

    // Provide full day of week name
    Date.prototype.getDayFull = function(){
        var days_full = [
                            'Sunday',
                            'Monday',
                            'Tuesday',
                            'Wednesday',
                            'Thursday',
                            'Friday',
                            'Saturday'
                        ];
        return days_full[this.getDay()];
    };

    // Provide full day of week name
    Date.prototype.getDayAbbr = function(){
        var days_abbr = [
                            'Sun',
                            'Mon',
                            'Tue',
                            'Wed',
                            'Thur',
                            'Fri',
                            'Sat'
                        ];
        return days_abbr[this.getDay()];
    };

    // Provide the day of year 1-365
    Date.prototype.getDayOfYear = function() {
        var onejan = new Date(this.getFullYear(),0,1);
        return Math.ceil((this - onejan) / 86400000);
    };

    // Provide the day suffix (st,nd,rd,th)
    Date.prototype.getDaySuffix = function() {
        var d = this.getDate();
        var sfx = ["th","st","nd","rd"];
        var val = d%100;

        return (sfx[(val-20)%10] || sfx[val] || sfx[0]);
    };

    // Provide Week of Year
    Date.prototype.getWeekOfYear = function() {
        var onejan = new Date(this.getFullYear(),0,1);
        return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
    } 

    // Provide if it is a leap year or not
    Date.prototype.isLeapYear = function(){
        var yr = this.getFullYear();

        if ((parseInt(yr)%4) == 0){
            if (parseInt(yr)%100 == 0){
                if (parseInt(yr)%400 != 0){
                    return false;
                }
                if (parseInt(yr)%400 == 0){
                    return true;
                }
            }
            if (parseInt(yr)%100 != 0){
                return true;
            }
        }
        if ((parseInt(yr)%4) != 0){
            return false;
        } 
    };

    // Provide Number of Days in a given month
    Date.prototype.getMonthDayCount = function() {
        var month_day_counts = [
                                    31,
                                    this.isLeapYear() ? 29 : 28,
                                    31,
                                    30,
                                    31,
                                    30,
                                    31,
                                    31,
                                    30,
                                    31,
                                    30,
                                    31
                                ];

        return month_day_counts[this.getMonth()];
    } 

    // format provided date into this.format format
    Date.prototype.format = function(dateFormat){
        // break apart format string into array of characters
        dateFormat = dateFormat.split("");

        var date = this.getDate(),
            month = this.getMonth(),
            hours = this.getHours(),
            minutes = this.getMinutes(),
            seconds = this.getSeconds();
        // get all date properties ( based on PHP date object functionality )
        var date_props = {
            d: date < 10 ? '0'+date : date,
            D: this.getDayAbbr(),
            j: this.getDate(),
            l: this.getDayFull(),
            S: this.getDaySuffix(),
            w: this.getDay(),
            z: this.getDayOfYear(),
            W: this.getWeekOfYear(),
            F: this.getMonthName(),
            m: month < 10 ? '0'+(month+1) : month+1,
            M: this.getMonthAbbr(),
            n: month+1,
            t: this.getMonthDayCount(),
            L: this.isLeapYear() ? '1' : '0',
            Y: this.getFullYear(),
            y: this.getFullYear()+''.substring(2,4),
            a: hours > 12 ? 'pm' : 'am',
            A: hours > 12 ? 'PM' : 'AM',
            g: hours % 12 > 0 ? hours % 12 : 12,
            G: hours > 0 ? hours : "12",
            h: hours % 12 > 0 ? hours % 12 : 12,
            H: hours,
            i: minutes < 10 ? '0' + minutes : minutes,
            s: seconds < 10 ? '0' + seconds : seconds           
        };

        // loop through format array of characters and add matching data else add the format character (:,/, etc.)
        var date_string = "";
        for(var i=0;i<dateFormat.length;i++){
            var f = dateFormat[i];
            if(f.match(/[a-zA-Z]/g)){
                date_string += date_props[f] ? date_props[f] : '';
            } else {
                date_string += f;
            }
        }

        return date_string;
    };
/*
 *
 * END - Date class extension
 * 
 ************************************/

How to format a JavaScript date - Stack Overflow

javascript date date-format time-format
Rectangle 27 14

Here's is some code I just wrote to handle the date formatting for a project I'm working on. It mimics the PHP date formatting functionality to suit my needs. Feel free to use it, it's just extending the already existing Date() object. This may not be the most elegant solution but it's working for my needs.

var d = new Date(); 
d_string = d.format("m/d/Y h:i:s");

/**************************************
 * Date class extension
 * 
 */
    // Provide month names
    Date.prototype.getMonthName = function(){
        var month_names = [
                            'January',
                            'February',
                            'March',
                            'April',
                            'May',
                            'June',
                            'July',
                            'August',
                            'September',
                            'October',
                            'November',
                            'December'
                        ];

        return month_names[this.getMonth()];
    }

    // Provide month abbreviation
    Date.prototype.getMonthAbbr = function(){
        var month_abbrs = [
                            'Jan',
                            'Feb',
                            'Mar',
                            'Apr',
                            'May',
                            'Jun',
                            'Jul',
                            'Aug',
                            'Sep',
                            'Oct',
                            'Nov',
                            'Dec'
                        ];

        return month_abbrs[this.getMonth()];
    }

    // Provide full day of week name
    Date.prototype.getDayFull = function(){
        var days_full = [
                            'Sunday',
                            'Monday',
                            'Tuesday',
                            'Wednesday',
                            'Thursday',
                            'Friday',
                            'Saturday'
                        ];
        return days_full[this.getDay()];
    };

    // Provide full day of week name
    Date.prototype.getDayAbbr = function(){
        var days_abbr = [
                            'Sun',
                            'Mon',
                            'Tue',
                            'Wed',
                            'Thur',
                            'Fri',
                            'Sat'
                        ];
        return days_abbr[this.getDay()];
    };

    // Provide the day of year 1-365
    Date.prototype.getDayOfYear = function() {
        var onejan = new Date(this.getFullYear(),0,1);
        return Math.ceil((this - onejan) / 86400000);
    };

    // Provide the day suffix (st,nd,rd,th)
    Date.prototype.getDaySuffix = function() {
        var d = this.getDate();
        var sfx = ["th","st","nd","rd"];
        var val = d%100;

        return (sfx[(val-20)%10] || sfx[val] || sfx[0]);
    };

    // Provide Week of Year
    Date.prototype.getWeekOfYear = function() {
        var onejan = new Date(this.getFullYear(),0,1);
        return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
    } 

    // Provide if it is a leap year or not
    Date.prototype.isLeapYear = function(){
        var yr = this.getFullYear();

        if ((parseInt(yr)%4) == 0){
            if (parseInt(yr)%100 == 0){
                if (parseInt(yr)%400 != 0){
                    return false;
                }
                if (parseInt(yr)%400 == 0){
                    return true;
                }
            }
            if (parseInt(yr)%100 != 0){
                return true;
            }
        }
        if ((parseInt(yr)%4) != 0){
            return false;
        } 
    };

    // Provide Number of Days in a given month
    Date.prototype.getMonthDayCount = function() {
        var month_day_counts = [
                                    31,
                                    this.isLeapYear() ? 29 : 28,
                                    31,
                                    30,
                                    31,
                                    30,
                                    31,
                                    31,
                                    30,
                                    31,
                                    30,
                                    31
                                ];

        return month_day_counts[this.getMonth()];
    } 

    // format provided date into this.format format
    Date.prototype.format = function(dateFormat){
        // break apart format string into array of characters
        dateFormat = dateFormat.split("");

        var date = this.getDate(),
            month = this.getMonth(),
            hours = this.getHours(),
            minutes = this.getMinutes(),
            seconds = this.getSeconds();
        // get all date properties ( based on PHP date object functionality )
        var date_props = {
            d: date < 10 ? '0'+date : date,
            D: this.getDayAbbr(),
            j: this.getDate(),
            l: this.getDayFull(),
            S: this.getDaySuffix(),
            w: this.getDay(),
            z: this.getDayOfYear(),
            W: this.getWeekOfYear(),
            F: this.getMonthName(),
            m: month < 10 ? '0'+(month+1) : month+1,
            M: this.getMonthAbbr(),
            n: month+1,
            t: this.getMonthDayCount(),
            L: this.isLeapYear() ? '1' : '0',
            Y: this.getFullYear(),
            y: this.getFullYear()+''.substring(2,4),
            a: hours > 12 ? 'pm' : 'am',
            A: hours > 12 ? 'PM' : 'AM',
            g: hours % 12 > 0 ? hours % 12 : 12,
            G: hours > 0 ? hours : "12",
            h: hours % 12 > 0 ? hours % 12 : 12,
            H: hours,
            i: minutes < 10 ? '0' + minutes : minutes,
            s: seconds < 10 ? '0' + seconds : seconds           
        };

        // loop through format array of characters and add matching data else add the format character (:,/, etc.)
        var date_string = "";
        for(var i=0;i<dateFormat.length;i++){
            var f = dateFormat[i];
            if(f.match(/[a-zA-Z]/g)){
                date_string += date_props[f] ? date_props[f] : '';
            } else {
                date_string += f;
            }
        }

        return date_string;
    };
/*
 *
 * END - Date class extension
 * 
 ************************************/

How to format a JavaScript date - Stack Overflow

javascript date date-format time-format
Rectangle 27 4

Instead of using loop try this code given below which is working(tested myself) fine as per your requirement

echo "data: This is the message.";
$url1="<your-page-name>.php";
header("Refresh: 5; URL=$url1");

what this will do is it will call itself every 5 seconds (in your case set it to 3 instead of 5) and echo the output.

php - While loops for server-sent events are causing page to freeze - ...

php server-sent-events
Rectangle 27 7

I realize I am a Johnny-Come-Lately here, but I was working with the VERY same problem -- and the tutorials I found out there would almost (but not quite upon unit testing) cover it.

After much frustration and research, here is what I cam up with

json_decode( json_encode( simplexml_load_string( $string ) ), TRUE );
  • XML attributes are not handled
  • Will also handle nested arrays with numeric indices (which are not valid XML!)
/// Converts an array to XML
/// - http://www.devexp.eu/2009/04/11/php-domdocument-convert-array-to-xml/
/// @param  <array> $array  The associative array you want to convert; nested numeric indices are OK!
function   getXml( array $array )  {

    $array2XmlConverter  = new XmlDomConstructor('1.0', 'utf-8');
    $array2XmlConverter->xmlStandalone   = TRUE;
    $array2XmlConverter->formatOutput    = TRUE;

    try {
        $array2XmlConverter->fromMixed( $array );
        $array2XmlConverter->normalizeDocument ();
        $xml    = $array2XmlConverter->saveXML();
//        echo "\n\n-----vvv start returned xml vvv-----\n";
//        print_r( $xml );
//        echo "\n------^^^ end returned xml ^^^----\n"
        return  $xml;
    }
    catch( Exception $ex )  {
//        echo "\n\n-----vvv Rut-roh Raggy! vvv-----\n";
//        print_r( $ex->getCode() );     echo "\n";
//        print_r( $->getMessage() );
//        var_dump( $ex );
//        echo "\n------^^^ end Rut-roh Raggy! ^^^----\n"
        return  $ex;
    }
}

... and here is the class to use for the $array2XmlConverter object:

/**
 * Extends the DOMDocument to implement personal (utility) methods.
 * - From: http://www.devexp.eu/2009/04/11/php-domdocument-convert-array-to-xml/
 * - `parent::` See http://www.php.net/manual/en/class.domdocument.php
 *
 * @throws   DOMException   http://www.php.net/manual/en/class.domexception.php
 *
 * @author Toni Van de Voorde
 */
class   XmlDomConstructor   extends DOMDocument {

    /**
     * Constructs elements and texts from an array or string.
     * The array can contain an element's name in the index part
     * and an element's text in the value part.
     *
     * It can also creates an xml with the same element tagName on the same
     * level.
     *
     * ex:
        \verbatim
             <nodes>
                <node>text</node>
                <node>
                    <field>hello</field>
                    <field>world</field>
                </node>
             </nodes>
        \verbatim
     *
     *
     * Array should then look like:
        \verbatim
             array(
                "nodes" => array(
                    "node" => array(
                        0 => "text",
                        1 => array(
                            "field" => array (
                                0 => "hello",
                                1 => "world",
                            ),
                        ),
                    ),
                ),
             );
        \endverbatim
     *
     * @param mixed $mixed An array or string.
     *
     * @param DOMElement[optional] $domElement Then element
     * from where the array will be construct to.
     *
     */
    public  function    fromMixed($mixed, DOMElement $domElement = null) {

        $domElement = is_null($domElement) ? $this : $domElement;

        if (is_array($mixed)) {
            foreach( $mixed as $index => $mixedElement ) {

                if ( is_int($index) ) {
                    if ( $index == 0 ) {
                        $node = $domElement;
                    } 
                    else {
                        $node = $this->createElement($domElement->tagName);
                        $domElement->parentNode->appendChild($node);
                    }
                }
                else {
                    $node = $this->createElement($index);
                    $domElement->appendChild($node);
                }

                $this->fromMixed($mixedElement, $node);
            }
        } 
        else {
            $domElement->appendChild($this->createTextNode($mixed));
        }
    }
} // end of class

Convert associative array to XML in PHP - Stack Overflow

php xml json
Rectangle 27 11

Try separating out the www and the trailing slash check. This is tested and hopefully working for you. You didn't say if you're running placing at domain root or in a subdirectory - usually good info when asking for help with htaccess.

RewriteEngine On

# Assuming you're running at domain root.  Change to working directory if needed.
RewriteBase /

#
# www check
# If you're running in a subdirectory, then you'll need to add that in
# to the redirected url (http://www.mydomain.com/subdirectory/$1

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

#
# Trailing slash check

# Don't fix direct file links
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

#
# Finally, forward everything to your front-controller

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [QSA,L]

To debug, comment out the individual sections and see what is/isn't working.

www

Tested and it still works fine for me. What part exactly isn't working? The trailing slash, the forward to index.php, or the www?

php - htaccess add trailing slash and force www with clean urls - Stac...

php .htaccess
Rectangle 27 3

Create unit tests for both! You need to know that it is working code!

PHP has a great unit testing tool known as PHPUnit, which offers a few ways of doing this. My recommendation would be to group the tests that are OS-specific with that OS name.

/**
 * @group linux
 */
class LinuxTest extends PHPUnit_Framework_TestCase {
    // all tests within this class will be in the group, linux 
}


class MixedTests extends PHPUnit_Framework_TestCase
{
    public function testSomeTestThatAlwaysRuns()
    {
        // this test is not in a group
    }

    /**
     * @group windows
     */
    public function testWindowsOnlyCase()
    {
        // this test is in the group, windows
    }
}

Then, when in linux, run all tests except for tests in "windows" and vice-versa. This will run all tests that should run on both platforms, and will only exclude those for the given group.

Also, you can exclude multiple groups:

phpunit --exclude-group windows,mac

Another use for this is to aid in TDD. In my environment, tests that are slow and/or hit the database have no group. Those that are fast are given a "@group fast" tag. This allows us to actively run tests on a lot of our code frequently during development, while still being able to get feedback regarding all of them once an hour or so.

php unit-testing windows linux
Rectangle 27 7

A session gets destroyed when the user closes the browser or leaves the site. The server also terminates the session after the predetermined period of session time expires. These are the simple mechanism steps that PHP is using to handle the session. I hope this article with help you to understand how PHP SESSION is working.

How do PHP sessions work? (not "how are they used?") - Stack Overflow

php session
Rectangle 27 7

A session gets destroyed when the user closes the browser or leaves the site. The server also terminates the session after the predetermined period of session time expires. These are the simple mechanism steps that PHP is using to handle the session. I hope this article with help you to understand how PHP SESSION is working.

How do PHP sessions work? (not "how are they used?") - Stack Overflow

php session
Rectangle 27 1

To check if the person name contains only number. The code below has been tested and is working

if the variable number contains any other thing that is not number it result in error. eg

$number = 'ABFRT001222288';
<?php
error_reporting(0);

    $string = 'ABTYUUU';
    if (!preg_match('/^[A-Z]*$/', $string)) {
        //error
echo 'Error does not contain only alphabet';
    } else {
        echo 'success. it contains only alphabets';
    }
?>

regex - How to user pregmatch in php - Stack Overflow

php regex
Rectangle 27 1

I think that it isn't working because you have only added an extra handler, you haven't removed the other handlers.

It is easiest to put another .htaccess file in the folder you want to protect (rather than messing with the match directive) that contains:

# Fix PHP, you should do matching commands for JSP and ASP, & html
RemoveType application/x-httpd-php php
# .... add the other remove-handler statements here .... #

# Optionally make these equivalent to text files.
# UPDATE: Taken this out as you dont want people to see PHP files at all
#AddType text/html php

# To disable cgi and server side includes & indexes
# You need to check the setup of Apache, some of the file types
# listed should already be handled as CGI (.pl, .py, .sh)
Options -ExecCGI -Includes -Indexes

# Completely block access to PHP files
<FilesMatch "\.(php|phps|html|htm|jsp|asp)$">
    Order allow,deny
    Deny from all
</Files>
# Add in any additional types to block

That covers PHP and CGI, you should do matching commands for JSP and ASP

UPDATE: Added code to completely block access to PHP files - sorry, thought initially that you simply didn't want them executing. Also note that I've commented out the line that turns PHP files into text files.

If you wish to keep all your config together in one file, you don't need a clever match directive, just put the config directives above inside a <Directory> block that refers to the dir you wish to configure

Correct @Cheekysoft. I generally prefer to put .htaccess files in the folder they belong to as it means they will still work even when moved. Still better of course is not to use them at all but to put them in the appropriate Apache configuration file if you have access to them.

i tried using your code in my .htaccess file inside the files directory but i can still access the .php file.

Updated to completely block access to a range of file types by extension. Simply adjust the regular expression to suite.

security - How can I prevent scripts from running inside a directory? ...

security .htaccess
Rectangle 27 1

You can try a working example here: http://jsfiddle.net/VQJ9V/307/ (Tested in FF 7, IE 9, Safari 5, Opera 11 and Chrome 14)

<div class="inputWrapper">
<input class="fileInput" type="file" name="file1"/>
.inputWrapper {
height: 32px;
width: 64px;
overflow: hidden;
position: relative;
cursor: pointer;
/*Using a background color, but you can use a background image to represent a button*/
background-color: #DDF;}
.fileInput {
cursor: pointer;
height: 100%;
position:absolute;
top: 0;
right: 0;
z-index: 99;
/*This makes the button huge. If you want a bigger button, increase the font size*/
font-size:50px;
/*Opacity settings for all browsers*/
opacity: 0;
-moz-opacity: 0;
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0)}

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

javascript - How to change the text "no file selected" next to the "Br...

javascript php html
Rectangle 27 5

The php module for apache registers itself as handler for the mime type application/x-httpd-php. And the configuration file apache\conf\extra\httpd-xampp.conf contains the lines

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

which tells the apache that all files having .php as name extension are to be processes by the handler for application/x-httpd-php. If you (really) want to have your .html files handled by the php module as well you have to add something similar for .html extensions. (there are other methods to tell the apache which extension maps to which mime type/handler. But FilesMatch/SetHandler is fine.) If you want to enable this "feature" for only one directory you can use an .htaccess file to change the configuration for that directory (and its subdirectories).

Thanks for your reply VolkerK. The script is working now that I've changed the .html extension to .php. However, if I click on the file, helloworld.php, Windows does not know the program that created it (even though I have Apache running). I am a bit puzzled, should I also install PHP for Windows?

"if I click on the file" - i.e. double-clicking in the windows explorer? Your Apache and the windows explorer are not connected, they "don't know" of each other. Your Apache handles http requests that e.g. your browser sends.

xampp - PHP script not working in HTML file - Stack Overflow

php xampp
Rectangle 27 1

Since you have said that the code is working on testing server and not on the production, than i assume nothing wrong with the code.

  • You can confirm that with curl test script provided by twitter api.

I am using VMware and the time was wrong after few pause and play! Made the time correct and boom it's working again. thanks pal :)

php - twitter api tmhOAuth is not working oauth/access_token - Stack O...

php twitter
Rectangle 27 4

Since AJAX happens "behind the scenes" (so to speak) your redirect will just interrupt the response to your javascript handler.

You'll need to return the URL and have your callback kick the browser to a new location.

On this note, since you have to return data to the front end, you'll want to add a status or similar variable so that you can switch your front end behavior based on whether the call "failed" or not.

In response to your solution, I strongly recommend against your form submission technique. As you say, it's not efficient, it's not pretty, and it requires twice the work (validating the user 2 times).

Why don't you use PHP's built in session handling to set a session if the user logs in successfully, and then simply check the session after a simple javascript browser redirect?

A javascript redirect is as simple as window.href = "http://mylocation" and if you don't know much about PHP's sessions, you could use this class I've built up (please disregard that it's also managing cookies, that's a silly oversight).

I am thinking by "status" variable, you're referring to implementing a solution similar to the one seen at the possible content duplicate link above ("How to manage a redirect..."), right?

Yes, very similar. I'm a big fan of creating PHP stdClass objects, then json_encode them to create a nice javascript object on the front end.

Thanks for the input. I will work on implementing the method as you suggested.

PHP not redirecting when working with Jquery post - Stack Overflow

php jquery
Rectangle 27 4

Since AJAX happens "behind the scenes" (so to speak) your redirect will just interrupt the response to your javascript handler.

You'll need to return the URL and have your callback kick the browser to a new location.

On this note, since you have to return data to the front end, you'll want to add a status or similar variable so that you can switch your front end behavior based on whether the call "failed" or not.

In response to your solution, I strongly recommend against your form submission technique. As you say, it's not efficient, it's not pretty, and it requires twice the work (validating the user 2 times).

Why don't you use PHP's built in session handling to set a session if the user logs in successfully, and then simply check the session after a simple javascript browser redirect?

A javascript redirect is as simple as window.href = "http://mylocation" and if you don't know much about PHP's sessions, you could use this class I've built up (please disregard that it's also managing cookies, that's a silly oversight).

I am thinking by "status" variable, you're referring to implementing a solution similar to the one seen at the possible content duplicate link above ("How to manage a redirect..."), right?

Yes, very similar. I'm a big fan of creating PHP stdClass objects, then json_encode them to create a nice javascript object on the front end.

Thanks for the input. I will work on implementing the method as you suggested.

PHP not redirecting when working with Jquery post - Stack Overflow

php jquery