Note that there are some explanatory texts on larger screens.

plurals
  1. POphp array function in class
    primarykey
    data
    text
    <p>I cant get this script to work, $users should hold the array data we take out of the database but it doesnt seem to work. Can anyone tell us what we are doing wrong? i posted the script bellow. </p> <p><em>added</em></p> <p>$users has to stay static becaus it gets used again later on in the script (this is just a small part) </p> <p>$user1 does get the right data it just doesnt get passed on to $users</p> <p>added</p> <p>this is the intire script hope that helps</p> <hr> <pre><code>&lt;?php class SingleSignOn_Server { public $links_path; protected $started=false; protected static $brokers = array( 'FGPostbus' =&gt; array('secret'=&gt;"FGPostbus123"), ); protected static $users = array(); public function query_personen(){ mysql_connect('host','user','pass') or die("Kan helaas geen verbinding maken" . mysql_error()); mysql_select_db('db') or die("Kan geen database selecteren"); $sql = mysql_query('select p_gebruikersnaam, p_wachtwoord, p_id, p_md5 FROM personen'); while ($row_user = mysql_fetch_assoc($sql)) { self::$users[] = $row_user; } } protected $broker = null; public function __construct() { if (!function_exists('symlink')) $this-&gt;links_path = sys_get_temp_dir(); } protected function sessionStart() { if ($this-&gt;started) return; $this-&gt;started = true; $matches = null; if (isset($_REQUEST[session_name()]) &amp;&amp; preg_match('/^SSO-(\w*+)-(\w*+)-([a-z0-9]*+)$/', $_REQUEST[session_name()], $matches)) { $sid = $_REQUEST[session_name()]; if (isset($this-&gt;links_path) &amp;&amp; file_exists("{$this-&gt;links_path}/$sid")) { session_id(file_get_contents("{$this-&gt;links_path}/$sid")); session_start(); setcookie(session_name(), "", 1); } else { session_start(); } if (!isset($_SESSION['client_addr'])) { session_destroy(); $this-&gt;fail("Not attached"); } if ($this-&gt;generateSessionId($matches[1], $matches[2], $_SESSION['client_addr']) != $sid) { session_destroy(); $this-&gt;fail("Invalid session id"); } $this-&gt;broker = $matches[1]; return; } session_start(); if (isset($_SESSION['client_addr']) &amp;&amp; $_SESSION['client_addr'] != $_SERVER['REMOTE_ADDR']) session_regenerate_id(true); if (!isset($_SESSION['client_addr'])) $_SESSION['client_addr'] = $_SERVER['REMOTE_ADDR']; } protected function generateSessionId($broker, $token, $client_addr=null) { if (!isset(self::$brokers[$broker])) return null; if (!isset($client_addr)) $client_addr = $_SERVER['REMOTE_ADDR']; return "SSO-{$broker}-{$token}-" . md5('session' . $token . $client_addr . self::$brokers[$broker]['secret']); } protected function generateAttachChecksum($broker, $token) { if (!isset(self::$brokers[$broker])) return null; return md5('attach' . $token . $_SERVER['REMOTE_ADDR'] . self::$brokers[$broker]['secret']); } public function login() { $this-&gt;sessionStart(); if (empty($_POST['p_gebruikersnaam'])) $this-&gt;failLogin("No user specified"); if (empty($_POST['p_wachtwoord'])) $this-&gt;failLogin("No password specified"); if (!isset(self::$users[$_POST['p_gebruikersnaam']]) || self::$users[$_POST['p_gebruikersnaam']]['p_wachtwoord'] != md5($_POST['p_wachtwoord'])) $this-&gt;failLogin("Incorrect credentials"); $_SESSION['user'] = $_POST['p_gebruikersnaam']; $this-&gt;info(); } public function logout() { $this-&gt;sessionStart(); unset($_SESSION['user']); echo 1; } public function attach() { $this-&gt;sessionStart(); if (empty($_REQUEST['broker'])) $this-&gt;fail("No broker specified"); if (empty($_REQUEST['token'])) $this-&gt;fail("No token specified"); if (empty($_REQUEST['checksum']) || $this-&gt;generateAttachChecksum($_REQUEST['broker'], $_REQUEST['token']) != $_REQUEST['checksum']) $this-&gt;fail("Invalid checksum"); if (!isset($this-&gt;links_path)) { $link = (session_save_path() ? session_save_path() : sys_get_temp_dir()) . "/sess_" . $this-&gt;generateSessionId($_REQUEST['broker'], $_REQUEST['token']); if (!file_exists($link)) $attached = symlink('sess_' . session_id(), $link); if (!$attached) trigger_error("Failed to attach; Symlink wasn't created.", E_USER_ERROR); } else { $link = "{$this-&gt;links_path}/" . $this-&gt;generateSessionId($_REQUEST['broker'], $_REQUEST['token']); if (!file_exists($link)) $attached = file_put_contents($link, session_id()); if (!$attached) trigger_error("Failed to attach; Link file wasn't created.", E_USER_ERROR); } if (isset($_REQUEST['redirect'])) { header("Location: " . $_REQUEST['redirect'], true, 307); exit; } header("Content-Type: image/png"); readfile("empty.png"); } public function info() { $this-&gt;sessionStart(); if (!isset($_SESSION['user'])) $this-&gt;failLogin("Not logged in"); header('Content-type: text/xml; charset=UTF-8'); echo '&lt;?xml version="1.0" encoding="UTF-8" ?&gt;', "\n"; echo '&lt;user identity="' . htmlspecialchars($_SESSION['user'], ENT_COMPAT, 'UTF-8') . '"&gt;'; echo ' &lt;p_id&gt;' . htmlspecialchars(self::$users[$_SESSION['user']]['p_id'], ENT_COMPAT, 'UTF-8') . '&lt;/p_id&gt;'; echo ' &lt;p_md5&gt;' . htmlspecialchars(self::$users[$_SESSION['user']]['p_md5'], ENT_COMPAT, 'UTF-8') . '&lt;/p_md5&gt;'; echo '&lt;/user&gt;'; } protected function fail($message) { header("HTTP/1.1 406 Not Acceptable"); echo $message; exit; } protected function failLogin($message) { header("HTTP/1.1 401 Unauthorized"); echo $message; exit; } } if (realpath($_SERVER["SCRIPT_FILENAME"]) == realpath(__FILE__) &amp;&amp; isset($_GET['cmd'])) { $ctl = new SingleSignOn_Server(); $ctl-&gt;$_GET['cmd'](); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload