snipt

Ctrl+h for KB shortcuts

Text only

.htaccess: Prevent website directory listing 1

Options -Indexes
https://snipt.net/embed/aaf2d87bdaf511f2cc54905f9701ed8d/
/raw/aaf2d87bdaf511f2cc54905f9701ed8d/
aaf2d87bdaf511f2cc54905f9701ed8d
text
Text only
2
2019-07-16T11:32:53
True
False
False
/api/public/snipt/54285/
htaccess-prevent-website-directory-listing
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>Options -Indexes </span></pre></div> </td></tr></table>
directory, htaccess, listing

PHP

PHP: Redirect page

1
2
3
4
5
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: howareyou.php");
exit();
?>
https://snipt.net/embed/df1029b5984d7be9e3d79c678e3e3e0a/
/raw/df1029b5984d7be9e3d79c678e3e3e0a/
df1029b5984d7be9e3d79c678e3e3e0a
php
PHP
5
2019-07-13T11:09:25
True
False
False
Jan 18, 2013 at 09:24 AM
/api/public/snipt/53971/
php-redirect-page
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">header</span><span class="p">(</span><span class="s2">&quot;HTTP/1.1 301 Moved Permanently&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">header</span><span class="p">(</span><span class="s2">&quot;Location: howareyou.php&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="k">exit</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
301, page, php, redirect

PHP

PDO: Update

1
2
3
4
5
<?php
$stmt = $db->prepare("UPDATE table SET name=? WHERE id=?");
$stmt->execute(array($name, $id));
$affected_rows = $stmt->rowCount();
?>
https://snipt.net/embed/a8a541866727d2e51793c352170cbb5c/
/raw/a8a541866727d2e51793c352170cbb5c/
a8a541866727d2e51793c352170cbb5c
php
PHP
5
2019-07-05T14:19:21
True
False
False
Jan 11, 2013 at 04:24 AM
/api/public/snipt/53145/
pdo-update
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s2">&quot;UPDATE table SET name=? WHERE id=?&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$name</span><span class="p">,</span> <span class="nv">$id</span><span class="p">));</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$affected_rows</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">rowCount</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"prepared statements", PDO, Update

PHP

PDO: Delete

1
2
3
4
5
6
<?php
$stmt = $db->prepare("DELETE FROM table WHERE id=:id");
$stmt->bindValue(':id', $id, PDO::PARAM_STR);
$stmt->execute();
$affected_rows = $stmt->rowCount();
?>
https://snipt.net/embed/d3266a244df1f38eac02526f4a93d918/
/raw/d3266a244df1f38eac02526f4a93d918/
d3266a244df1f38eac02526f4a93d918
php
PHP
6
2019-07-16T09:38:44
True
False
False
/api/public/snipt/53144/
pdo-delete
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s2">&quot;DELETE FROM table WHERE id=:id&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">bindValue</span><span class="p">(</span><span class="s1">&#39;:id&#39;</span><span class="p">,</span> <span class="nv">$id</span><span class="p">,</span> <span class="nx">PDO</span><span class="o">::</span><span class="na">PARAM_STR</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$affected_rows</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">rowCount</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"prepared statements", PDO, delete

PHP

PDO: Insert

1
2
3
4
5
6
7
<?php
/* Prepared Statements for INSERT */

$stmt = $db->prepare("INSERT INTO table(field1,field2,field3,field4,field5) VALUES(:field1,:field2,:field3,:field4,:field5)");
$stmt->execute(array(':field1' => $field1, ':field2' => $field2, ':field3' => $field3, ':field4' => $field4, ':field5' => $field5));
$affected_rows = $stmt->rowCount();
?>
https://snipt.net/embed/14f5696754b9d3ef56930e5293602e48/
/raw/14f5696754b9d3ef56930e5293602e48/
14f5696754b9d3ef56930e5293602e48
php
PHP
7
2019-07-14T19:47:28
True
False
False
Jan 11, 2013 at 04:22 AM
/api/public/snipt/53143/
pdo-insert
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="cm">/* Prepared Statements for INSERT */</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s2">&quot;INSERT INTO table(field1,field2,field3,field4,field5) VALUES(:field1,:field2,:field3,:field4,:field5)&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;:field1&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field1</span><span class="p">,</span> <span class="s1">&#39;:field2&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field2</span><span class="p">,</span> <span class="s1">&#39;:field3&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field3</span><span class="p">,</span> <span class="s1">&#39;:field4&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field4</span><span class="p">,</span> <span class="s1">&#39;:field5&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field5</span><span class="p">));</span> </span><span id="L-6"><a name="L-6"></a><span class="nv">$affected_rows</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">rowCount</span><span class="p">();</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"prepared statements", PDO, insert, placeholders

PHP

PDO: Select with named placeholders

1
2
3
4
5
6
7
<?php
$stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name");
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
https://snipt.net/embed/8599116abd19627cf0b9206fae7be40f/
/raw/8599116abd19627cf0b9206fae7be40f/
8599116abd19627cf0b9206fae7be40f
php
PHP
7
2019-07-11T06:30:55
True
False
False
/api/public/snipt/53142/
pdo-select-with-named-placeholders
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s2">&quot;SELECT * FROM table WHERE id=:id AND name=:name&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">bindValue</span><span class="p">(</span><span class="s1">&#39;:id&#39;</span><span class="p">,</span> <span class="nv">$id</span><span class="p">,</span> <span class="nx">PDO</span><span class="o">::</span><span class="na">PARAM_INT</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">bindValue</span><span class="p">(</span><span class="s1">&#39;:name&#39;</span><span class="p">,</span> <span class="nv">$name</span><span class="p">,</span> <span class="nx">PDO</span><span class="o">::</span><span class="na">PARAM_STR</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">execute</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="nv">$rows</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-&gt;</span><span class="na">fetchAll</span><span class="p">(</span><span class="nx">PDO</span><span class="o">::</span><span class="na">FETCH_ASSOC</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"named placeholders", "prepared statements", PDO, placeholders