<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>phorum_api_user_save()</title>
        <description> i&amp;#039;ve received some strange behaviour from this api function...

if you need background, you can catch up by reading my most recents started threads

so on my main site, i get the user info that phorum_api_user_save() requires

    if ($user) {
// only if login
        $our_user[&amp;#039;user_id&amp;#039;] = $user[&amp;#039;id&amp;#039;];
        $our_user[&amp;#039;username&amp;#039;] = $user[&amp;#039;username&amp;#039;];
        $our_user[&amp;#039;password&amp;#039;] = $user[&amp;#039;userpass&amp;#039;];
        $our_user[&amp;#039;email&amp;#039;] = $user[&amp;#039;email&amp;#039;];
    } elseif (!$user) {
// anytime other than login
        $our_user[&amp;#039;user_id&amp;#039;] = getsession()-&amp;gt;m_userInfo[&amp;#039;id&amp;#039;];
        $our_user[&amp;#039;username&amp;#039;] = getsession()-&amp;gt;m_userInfo[&amp;#039;username&amp;#039;];
        $our_user[&amp;#039;password&amp;#039;] = getsession()-&amp;gt;m_userInfo[&amp;#039;userpass&amp;#039;];
        $our_user[&amp;#039;email&amp;#039;] = getsession()-&amp;gt;m_userInfo[&amp;#039;email&amp;#039;];
    } else {
        $session-&amp;gt;addError(&amp;quot;puke&amp;quot;);
    }
    $our_user[&amp;#039;admin&amp;#039;] = 0;
    $our_user[&amp;#039;active&amp;#039;] = 1;

after this i check if the user is an admin on my site and change [&amp;#039;admin&amp;#039;] to 1. then i send it just like that to phorum_api_user_save, look at the variables, then die.


    chdir($phorumdir);
        include_once(&amp;quot;common.php&amp;quot;);
        $phorum_api_user_save = phorum_api_user_save($our_user, PHORUM_FLAG_RAW_PASSWORD);
    chdir($mydir);
    echo var_dump($phorum_api_user_save).&amp;quot;&amp;lt;hr&amp;gt;&amp;quot;;
    echo var_dump($our_user).&amp;quot;&amp;lt;hr&amp;gt;&amp;quot;;
    die();

so to setup, i delete the phorum database entry and cookie, and then i delete my cookie and the &amp;quot;copy successful&amp;quot; flag.

with the user logged out, my site gives a generic index with login fields. when a user logs in, here&amp;#039;s the output.


int(0)
array(6) { [&amp;quot;user_id&amp;quot;]=&amp;gt;  string(1) &amp;quot;6&amp;quot; [&amp;quot;username&amp;quot;]=&amp;gt;  string(3) &amp;quot;rod&amp;quot; [&amp;quot;password&amp;quot;]=&amp;gt;  string(32) &amp;quot;7ddf32e17a6ac5ce04a8ecbf782ca509&amp;quot; [&amp;quot;email&amp;quot;]=&amp;gt;  string(15) &amp;quot;rod@example.com&amp;quot; [&amp;quot;admin&amp;quot;]=&amp;gt;  int(0) [&amp;quot;active&amp;quot;]=&amp;gt;  int(1) }

int (0) being the result of the api.

here&amp;#039;s where it gets XFiles.

the data that i gave it seems to be alright i thought but the api returns a ZERO, meaning failed save. the headscratcher part is in the db there&amp;#039;s an actual half save. . . it actually saved the userid and username, and nothing else.

alright... more peculiar behaviour... login to my site a 2nd time (back one page, submit again) heres the output.


int(6)
array(6) { [&amp;quot;user_id&amp;quot;]=&amp;gt;  string(1) &amp;quot;6&amp;quot; [&amp;quot;username&amp;quot;]=&amp;gt;  string(3) &amp;quot;rod&amp;quot; [&amp;quot;password&amp;quot;]=&amp;gt;  string(32) &amp;quot;7ddf32e17a6ac5ce04a8ecbf782ca509&amp;quot; [&amp;quot;email&amp;quot;]=&amp;gt;  string(15) &amp;quot;rod@example.com&amp;quot; [&amp;quot;admin&amp;quot;]=&amp;gt;  int(0) [&amp;quot;active&amp;quot;]=&amp;gt;  int(1) }

in looking at the db, this time it completed the write. it even took the time to set other profile friendly fields like pm_email_notify=1 and others.

primary question: this isn&amp;#039;t intended behaviour is it? I mean 1 write is supposed to be all it needs right?

2ndary question, meaning the above is more important than this one, if all i send is username and id, will it puke on credentials at some point in the future without password even tho phorum auth is bypassed completely?</description>
        <link>https://www.phorum.org/support/read.php?28,132016,132016#msg-132016</link>
        <lastBuildDate>Wed, 18 Nov 2026 07:46:41 -0600</lastBuildDate>
        <generator>Phorum 6.0.4</generator>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132666#msg-132666</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132666#msg-132666</link>
            <description><![CDATA[ You print your header before Phorum sets a cookie, therefore the error happens. It is a really common PHP error message.<br />
<br />
One way to solve it can be to start your script with a call to ob_start(). That will keep back the output till the end of the request, so headers can be sent at any time.<br />
<br />
If you use user_session_restore, then Phorum does not need to keep track of cookies to maintain a session. You can implement the hook user_session_create and let the implementation function return NULL to flag Phorum that it should not run its own session handler. Take a look at the developer documentation for a full description of this hook.]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Mon, 18 Aug 2008 11:54:33 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132079#msg-132079</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132079#msg-132079</link>
            <description><![CDATA[ no not the login <i>page</i> . . . not unless 1 or both of those functions do. <br />
<br />
I&#039;ve now been told ppl get an error message. . . but only once. tho i&#039;ve never seen it, it may be the windows to the soul of the culprit. . . <br />
<pre class="bbcode">
Warning: Cannot modify header information - headers already sent by (output started at /path/to/my/handler.php:25) in /path/to/my/forum/include/api/user.php on line 2138</pre>
<br />
that line in my handler.php is the first line of output by my page-display abstraction <br />
<pre class="bbcode">
echo &quot;&lt;&quot;.&#039;?&#039;.&#039;xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;&#039;.&#039;?&#039;.&quot;&gt;\n&quot;;</pre>
<br />
whereas that exact line in user.php is <br />
            <pre class="bbcode">
);</pre>
<br />
at the end of what looks to be the cookie maker part of the function phorum_api_user_session_create. not sure what that&#039;s all about, but it leads me to believe that the error msg might somehow be related to the performance culprit.<br />
<br />
it also makes me wonder . . . since i currently have the site set to &quot;require cookies&quot; in addition to using &quot;user_session_restore&quot; hook based on my own auth . . . i suppose cookies technically aren&#039;t explicitly required with this combo?]]></description>
            <dc:creator>sazaraki</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Wed, 23 Jul 2008 00:05:24 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132066#msg-132066</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132066#msg-132066</link>
            <description><![CDATA[ You mean you are hitting your login page here over and over again, causing phorum_api_user_save() to be hit over and over again as well? It is not two queries that are run. Without looking at the code, I&#039;d say at least one more (phorum_api_usre_get() to lookup the user to see if it&#039;s an existing user or not).<br />
<br />
I&#039;m not sure what you are doing exactly, but it might be useful to change the table type for the users table to innodb if you to not already use that as the default table type for your MySQL server. That might help resolving some concurrency issues that you might be having when pushing the code at this rate.]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Tue, 22 Jul 2008 01:33:19 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132064#msg-132064</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132064#msg-132064</link>
            <description><![CDATA[ how many queries does this run? sounds like 2 fairly simple ones.<br />
<br />
user auth is 2 step: guy logsin to the main site, their info is copied to phorum using api_user_save. when they go to the forum, user_session_restore creates credentials based on the mainsite auth.<br />
<br />
i activated the copy function, but didn&#039;t open the forum for use so the only use it was getting was api_user_save. on my db, queries per second jumped from ~300 to &gt;900 average  . . . and it was only getting ~100 copies/minute after a while. on top of that, i couldn&#039;t see what queries were causing all that (mtop wouldn&#039;t show)]]></description>
            <dc:creator>sazaraki</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Tue, 22 Jul 2008 00:37:31 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132026#msg-132026</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132026#msg-132026</link>
            <description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>sazaraki</strong><br />meantime, wht&#039;s the define for?</div></blockquote>
<br />
It&#039;s just to keep some warnings from happening, because in common.php the value of this define is checked at several places. Each Phorum script is expected to have a define for &quot;phorum_page&quot; set. The exact value does not exactly matter. As long as you don&#039;t use any of the default phorum_page defines it is okay.]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 14:07:53 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132025#msg-132025</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132025#msg-132025</link>
            <description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>Maurice Makaay</strong><br />
Who told you to turn auto_increment off? Did we?</div></blockquote>
<br />
No. i was having. . . odd . . . issues previously, and it was acting similarly. since we&#039;re not using phorum to build users, it was suggested as a shrugging stab at fixing it.<br />
<br />
<blockquote class="bbcode"><div><small>Quote<br /></small><strong>DavidVB</strong><br />
The api does a two step process, first saving the user_id and name. It uses a php call to determine the user_id that was inserted, then puts in the rest of the data. This call doesn&#039;t work if the field is not autoincremented. Turn it back on and the data insert should work.</div></blockquote>
<br />
i did that, and there it went. thanks for your help!]]></description>
            <dc:creator>sazaraki</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:52:48 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132024#msg-132024</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132024#msg-132024</link>
            <description><![CDATA[ i&#039;m working on it now it&#039;s gonna take a bit cuz i have some funky rewrites n crap going on, so it&#039;ll take a bit of setup. <br />
<br />
meantime, wht&#039;s the define for?]]></description>
            <dc:creator>sazaraki</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:49:20 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132023#msg-132023</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132023#msg-132023</link>
            <description><![CDATA[ Who told you to turn auto_increment off? Did we?]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:22:20 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132022#msg-132022</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132022#msg-132022</link>
            <description><![CDATA[ The api does a two step process, first saving the user_id and name. It uses a php call to determine the user_id that was inserted, then puts in the rest of the data. This call doesn&#039;t work if the field is not autoincremented. Turn it back on and the data insert should work.]]></description>
            <dc:creator>DavidVB</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:21:52 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132021#msg-132021</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132021#msg-132021</link>
            <description><![CDATA[ <blockquote class="bbcode"><div><small>Quote<br /></small><strong>DavidVB</strong><br />
In your phorum user table is the user_id field autoincrement?</div></blockquote>
<br />
it was before when i was having this. and it was suggested to turn it off as a &quot;well try that and see what happens&quot; kinda thing]]></description>
            <dc:creator>sazaraki</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:17:21 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132020#msg-132020</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132020#msg-132020</link>
            <description><![CDATA[ Last question first: no puking involved. It&#039;s okay to leave the passwords out. Only for the admin, you need to set the password (unless you have the authentication for that inherited by the other code too, I don&#039;t do that myself).<br />
<br />
First question: I ran this test script on my 5.2 system:<br />
<br />
<pre class="bbcode">
&lt;?php

define(&#039;phorum_page&#039;,&#039;test&#039;);

include_once(&quot;./common.php&quot;);

$user = array(
    &#039;user_id&#039;  =&gt; &#039;666&#039;,
    &#039;username&#039; =&gt; &#039;rod&#039;,
    &#039;password&#039; =&gt; &#039;7ddf32e17a6ac5ce04a8ecbf782ca509&#039;,
    &#039;email&#039;    =&gt; &#039;rod@example.com&#039;,
    &#039;admin&#039;    =&gt; 0,
    &#039;active&#039;   =&gt; 1
);

$ret = phorum_api_user_save($user, PHORUM_FLAG_RAW_PASSWORD);

var_dump($ret);

?&gt;</pre>
<br />
The output for this script was:<br />
<br />
<pre class="bbcode">
int(666)</pre>
<br />
That is exactly what I expected. A return value of zero is not expected.<br />
<br />
Can you try this basic script on your system too? (with the data a bit updated to prevent duplicate users).]]></description>
            <dc:creator>Maurice Makaay</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:08:40 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132019#msg-132019</guid>
            <title>Re: phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132019#msg-132019</link>
            <description><![CDATA[ In your phorum user table is the user_id field autoincrement?]]></description>
            <dc:creator>DavidVB</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 13:04:39 -0500</pubDate>
        </item>
        <item>
            <guid>https://www.phorum.org/support/read.php?28,132016,132016#msg-132016</guid>
            <title>phorum_api_user_save()</title>
            <link>https://www.phorum.org/support/read.php?28,132016,132016#msg-132016</link>
            <description><![CDATA[ i&#039;ve received some strange behaviour from this api function...<br />
<br />
<i>if you need background, you can catch up by reading my most recents started threads</i><br />
<br />
so on my main site, i get the user info that phorum_api_user_save() requires<br />
<pre class="bbcode">
    if ($user) {
// only if login
        $our_user[&#039;user_id&#039;] = $user[&#039;id&#039;];
        $our_user[&#039;username&#039;] = $user[&#039;username&#039;];
        $our_user[&#039;password&#039;] = $user[&#039;userpass&#039;];
        $our_user[&#039;email&#039;] = $user[&#039;email&#039;];
    } elseif (!$user) {
// anytime other than login
        $our_user[&#039;user_id&#039;] = getsession()-&gt;m_userInfo[&#039;id&#039;];
        $our_user[&#039;username&#039;] = getsession()-&gt;m_userInfo[&#039;username&#039;];
        $our_user[&#039;password&#039;] = getsession()-&gt;m_userInfo[&#039;userpass&#039;];
        $our_user[&#039;email&#039;] = getsession()-&gt;m_userInfo[&#039;email&#039;];
    } else {
        $session-&gt;addError(&quot;puke&quot;);
    }
    $our_user[&#039;admin&#039;] = 0;
    $our_user[&#039;active&#039;] = 1;</pre>
<br />
after this i check if the user is an admin on my site and change <i>[&#039;admin&#039;] to 1</i>. then i send it just like that to phorum_api_user_save, look at the variables, then die.<br />
<br />
<pre class="bbcode">
    chdir($phorumdir);
        include_once(&quot;common.php&quot;);
        $phorum_api_user_save = phorum_api_user_save($our_user, PHORUM_FLAG_RAW_PASSWORD);
    chdir($mydir);
    echo var_dump($phorum_api_user_save).&quot;&lt;hr&gt;&quot;;
    echo var_dump($our_user).&quot;&lt;hr&gt;&quot;;
    die();</pre>
<br />
so to setup, i delete the phorum database entry and cookie, and then i delete my cookie and the &quot;copy successful&quot; flag.<br />
<br />
with the user logged out, my site gives a generic index with login fields. when a user logs in, here&#039;s the output.<br />
<br />
<pre class="bbcode">
int(0)
array(6) { [&quot;user_id&quot;]=&gt;  string(1) &quot;6&quot; [&quot;username&quot;]=&gt;  string(3) &quot;rod&quot; [&quot;password&quot;]=&gt;  string(32) &quot;7ddf32e17a6ac5ce04a8ecbf782ca509&quot; [&quot;email&quot;]=&gt;  string(15) &quot;rod@example.com&quot; [&quot;admin&quot;]=&gt;  int(0) [&quot;active&quot;]=&gt;  int(1) }</pre>
<br />
int (0) being the result of the api.<br />
<br />
here&#039;s where it gets XFiles.<br />
<br />
the data that i gave it seems to be alright i thought but the api returns a ZERO, meaning failed save. the headscratcher part is in the db there&#039;s an actual half save. . . it actually saved the userid and username, and nothing else.<br />
<br />
alright... more peculiar behaviour... login to my site a 2nd time (back one page, submit again) heres the output.<br />
<br />
<pre class="bbcode">
int(6)
array(6) { [&quot;user_id&quot;]=&gt;  string(1) &quot;6&quot; [&quot;username&quot;]=&gt;  string(3) &quot;rod&quot; [&quot;password&quot;]=&gt;  string(32) &quot;7ddf32e17a6ac5ce04a8ecbf782ca509&quot; [&quot;email&quot;]=&gt;  string(15) &quot;rod@example.com&quot; [&quot;admin&quot;]=&gt;  int(0) [&quot;active&quot;]=&gt;  int(1) }</pre>
<br />
in looking at the db, this time it completed the write. it even took the time to set other profile friendly fields like pm_email_notify=1 and others.<br />
<br />
primary question: this isn&#039;t intended behaviour is it? I mean 1 write is supposed to be all it needs right?<br />
<br />
2ndary question, meaning the above is more important than this one, if all i send is username and id, will it puke on credentials at some point in the future without password even tho phorum auth is bypassed completely?]]></description>
            <dc:creator>sazaraki</dc:creator>
            <category>Phorum Integration</category>
            <pubDate>Sun, 20 Jul 2008 11:40:01 -0500</pubDate>
        </item>
    </channel>
</rss>
