Disable direct access to files in PHP

Mr Me’s Question:

I’ve already checked the issue disable access to included files , but I am wondering if that’s the best solution.

Context: I’m building a bootstrap class for my PHP Framework, and realized that there are multiple solutions to this security issue.

After researching and reading posts like the one I mentioned at first and others related to htaccess, I think that there are basically three types of solutions:

1 – Checking a constant (like in the post I linked)

if(!defined('THIS_IS_NOT_A_DIRECT_ACCESS')) {
    header('HTTP/1.1 404 Not Found');
    include('./../error/404.php');
    die;
}

Or

require('../error/include_file.php');
//
if(!defined('THIS_IS_NOT_A_DIRECT_ACCESS'))
{
    header('HTTP/1.1 404 Not Found');
    include('404.php');  
    die; 
}

2 – Redirecting all calls to the Bootstrap and making a clever filtering.

Read the rest

Selecting more than one option

User2386255′s Question:

I have the following code working pretty well, but I want to be able to select more than one option if need be: http://jsfiddle.net/exlondoner/MKa3n/

Can anyone help?

JS:

$('.media-select-option').on('click', function() {
    $('.media-select-option').removeClass('selected');
    $(this).addClass('selected');     
    $('.m-overlay-close-btn').addClass('checked');       
});

Try this:

$('.media-select-option').on('click', function () {
    $(this).toggleClass('selected');
    $('.m-overlay-close-btn').addClass('checked');
});

FIDDLE

It is not working because there is no such element with class m-overlay-close-btn

$('.overlay-close-btn').addClass('checked');

Working fiddle

Read the rest

Dropdown Menu CSS

Wizzme’s Question:

I cannot figure out what is wrong with my dropdown menu. When I over over the main level link, the drop down appear but at the left of my screen instead of underneath the main link.
I have been on this for a couple of hours and any help would be greatly appreciated.

Here is the html part :

<div class="nav">

        <ul id="menu">
           <li><a href="#" class="current">Home</a></li>
              <li><a href="#">Apetiziers</a>
              <ul>
               <li><a href="#">Sub-Link 1</a></li>
               <li><a href="#">Sub-Link 2</a></li>
               <li><a href="#">Sub-Link 3</a></li>
               <li><a href="#">Sub-Link 4</a></li>
              </ul>
              </li>

              <li><a href="#">Entree</a>
             <ul>
             <li><a href="#">Sub-Link 1</a></li>
             <li><a href="#">Sub-Link 2</a></li>
             <li><a href="#">Sub-Link 3</a></li>
             <li><a href="#">Sub-Link 4</a></li>
             </ul>
              </li>

              <li><a href="#">Main Course</a>
             <ul>
             <li><a href="#">Sub-Link 1</a></li>
             <li><a href="#">Sub-Link 2</a></li>
             <li><a href="#">Sub-Link 3</a></li>
             <li><a href="#">Sub-Link 4</a></li>
             </ul>      
              </li>

              <li><a href="#">Dessert</a>
             <ul>
              <li><a href="#">Sub-Link 1</a></li>
              <li><a href="#">Sub-Link 2</a></li>
              <li><a href="#">Sub-Link 3</a></li>
              <li><a href="#">Sub-Link 4</a></li>
             </ul>      
              </li>


              <li><a href="#">Contact Us</a></li>
        </ul>

 </div>

And the .css :

ul#menu {
   float: left;
  margin: 0;
  width: auto;
    padding: 0px 40px 0px;
    background: #333; color: #fff;
    line-height: 100%;
}

ul#menu li {
  display: inline; 
}


/* top level link */
ul#menu a {
  float: left;
  padding: 10px 16px;
  margin-right: 0px;
  background: #789; color: #fff;
  text-decoration: none;
  border-right: 1px solid #e2e2e2;
}

/* main level link hover */
ul#menu a.current {
  background: #f60; color: #fff;
}


ul#menu li:hover > a {
  color: #fff; background: #ff4500;
  text-decoration: underline;
}

/* dropdown */
ul#menu li:hover > ul {
    display: block; /* shows the sub-menu (child ul of li) on hover */
}

/* sub level list */
ul#menu ul {
    display: none; /* hides the sub-menu until you hover over it */
    margin: 0;
    padding: 0;
    width: 140px;
    position: absolute;
    top: 35px;
    left: 0;
    background: #000;
    border: solid 1px #ccc;
}

ul#menu ul li {
    float: none;
    margin: 0;
    padding: 0;
}

ul#menu ul a {
    font-weight: normal;
    background: #9BB3BF; color: #036;
}

/* sub levels link hover */
ul#menu ul li a:hover {
color: #036; background: #DDDF99;
}

It is probably jumping towards the closest relative container.

Read the rest

Fetching result isn't working after prepared statement

Jskidd3′s Question:

I’m struggling to write this myself so I will say what I know I need to do and what I have already.

Based on two $_GET[] variables I need to query a database. The values provide me with the table name and the name of the location. From this location field name, I need to extrapolate the whole row.

So, I query the database with this data, however when I try and fetch and print it nothing happens. I need the whole row’s data (in an array?).

I understand my code is ugly. And probably vulnerable to MySQL injection, but I would rather get my PHP right in terms of getting the row into an array before I worry about that.

Read the rest

Apache is not executing PHP scripts

User2495173′s Question:

I changed the httpd.conf as follows:

  • Replaced

    DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
    

    with

    DocumentRoot "C:/Temp/WebServerCore/Binaries/html"
    
  • Replaced

    <Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
    

    with

    <Directory "C:/Temp/WebServerCore/Binaries/html">
    

However Apache does not recognize the php code in my .html file. What other changes do I need to make for Apache to execute PHP?

It is by design. Apache will not parse PHP code inside a HTML file by default. You can include HTML codes in a PHP file as you would code them in a HTML document.

Renames your files and add extension .php at the end they will parsed as you want.

Read the rest

why i cant empty textarea when i enter

HiDd3N’s Question:

i just setup a jsfiddle in this link and the problem is where i empty textarea one line break stay and i cant see placeholder again and i always one break line is there see this fiddle

http://jsfiddle.net/W5WE8/

my html

<script src="http//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<textarea id="mytextarea" rows="15" cols="80" placeholder="write something and press enter"></textarea>

and here is my js

$('#mytextarea').keydown(function(e) {
        if (e.keyCode == 13) {
            $('#mytextarea').val('').focus();
        }
    });

You need to prevent the default behaviour of the keydown. As seen here: http://jsfiddle.net/lnrb0b/W5WE8/2/

$('#mytextarea').keydown(function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        $('#mytextarea').val('').focus();
    }
});

Hope that helps :)

The main reason why this is happening is because of the enter key.

Read the rest

How to hide Partial Data in PHP

Sameer007860′s Question:

Eperimenting PHP just for fun, But As being newbie, I’m unable to understand curcial parts of PHP….Please help me to sort out this problem which I’m explaining by example :

Suppose

$sql = "SELECT id, text,uid FROM feeds WHERE uid='".$ud."' LIMIT 10";
$items = mysql_query($sql);
echo mysql_error();

if (@mysql_num_rows($items) > 0)
{
    while ($item = mysql_fetch_array($items))
    {
        $feed = $item[1];
        $nick = getnick($item[2]);
    }
}

So I want to display like this :

3 Records with uid details…

jay,vicky, sumair and 17 others like this.

Please help me to get output of something like this !!

Thanks !!

Read the rest

Javascript method is not working on Firefox

Merand’s Question:

My stylesheet is working on ie, however it isnt working on firefox. It gives an error such as:

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable @
TypeError: document.getElementById(…) is null.

Here is my code:

<script style="javascript">
    function displayRevision2() {
        for (i = 1; i & lt; j; i++) {
            foo = document.getElementById('row' + i).innerHTML;
            substring = foo.substr(0, foo.search("n") - 1);
            //displayRevision(substring);   
            if (flag == 1) document.getElementById(substring).style.display = "";
            else document.getElementById(substring).style.display = "none";
        }
        if (flag == 1) flag = 0;
        else flag = 1;
    }
</script>
<script style="javascript">
    function dispTD(num) {
        rowtxt = '&lt;TD class="br" align="middle" id="row' + num + '">';
        document.write(rowtxt);
    }
</script>
<script style="javascript">
    function dispEndTD() {
        document.write("&lt;/TD>");
    }
</script>

It may be because the element the script is searching for does not exist on the document.

Read the rest

&lt;h1&gt; Header (vs h2, h3, etc)

User1994136′s Question:

I have 3 header tags.
My setup:

h1

h2

h3

QUESTION: My h3 tag is the most important (for SEO). All 3 have the same indent so I don’t want those changed in any way. If you can help me, what I need to know is:

Since h1 is seen by SEs as most important, am I allowed to rename my current h3 into h1 and vice versa, so that they are in this

order? …

h3

h2

h1

…OR does h1 always have to be “first” in the crawl? Basically I want to tell Google etc that my current h3 is far more important than my current h1 & h2.

Read the rest

What does &quot;+&quot; mean in css. Help me?

Smartuser’s Question:

What does the “+” symbol stand for in css style. What does the below code infer
#mainDiv label + a { }

+ means adjacent selector.

In your case it means if <a> tag is found directly after <label> tag inside the mainDiv then apply the css.

Read the rest