Skip to content

Instantly share code, notes, and snippets.

View iNaD's full-sized avatar

Daniel Gehn iNaD

View GitHub Profile
@iNaD
iNaD / addhost.bat
Created February 13, 2015 15:33
[Windows] Add a new host to your hosts File
@echo off
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: No administrative permissions.
exit /B
@iNaD
iNaD / request_no_curl.php
Last active February 29, 2024 09:37
Sending a GET/POST Request via PHP without CURL (fopen needs to be enabled)
<?php
$url = 'http://server.com/path';
$data = array('key1' => 'value1', 'key2' => 'value2');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
@iNaD
iNaD / csrf.php
Last active December 14, 2015 01:39
Simple snippet to harden your forms against CSRF (see http://en.wikipedia.org/wiki/Cross-site_request_forgery).
<?php
function create_csrf_field()
{
$field_hash = hash('sha256', time().'some_salt');
$hash = hash('sha256', 'some_salt'.time().rand(0,10));
$_SESSION['csrf_field'] = $field_hash;
$_SESSION['csrf_hash'] = $hash;
return '<input type="hidden" name="'.$field_hash.'" value="'.$hash.'">';
}