Last active
August 29, 2015 14:18
-
-
Save floriancourgey/d099ff3d5492417ae62a to your computer and use it in GitHub Desktop.
NewbieContest php curl connexion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><?= $titre ?></title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<?php | |
define("SMFCookie89", ""); | |
define("PHPSESSID", ""); | |
function get($relativeUrl){ | |
$c = curl_init("http://www.newbiecontest.org/".$relativeUrl); | |
curl_setopt($c, CURLOPT_COOKIE, getCookies()) ; | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, true); | |
$retour = curl_exec ($c); | |
curl_close($c); | |
return $retour; | |
} | |
function post($relativeUrl, $array){ | |
// conversion de l'array en données post html | |
$fields_string = ''; | |
foreach($array as $key=>$value){ | |
$fields_string .= 'rep'.($key+1).'='.$value.'&'; | |
} | |
rtrim($fields_string, '&'); | |
$c = curl_init("http://www.newbiecontest.org/".$relativeUrl); | |
curl_setopt($c, CURLOPT_POST, count($array)); | |
curl_setopt($c, CURLOPT_POSTFIELDS, $fields_string); | |
curl_setopt($c, CURLOPT_COOKIE, getCookies()) ; | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
$retour = curl_exec ($c); | |
curl_close($c); | |
return $retour; | |
} | |
function getCookies(){ | |
$cookies = "SMFCookie89=".SMFCookie89.";"; | |
if(defined(PHPSESSID)){ | |
$cookies .= "PHPSESSID=".PHPSESSID; | |
} | |
return $cookies; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('context.php'); | |
$retour = get("epreuves/prog/frok-fichus_nb/prog_2.php"); | |
echo $retour; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment