PDA

View Full Version : PHP Module loses user session info on form submit


Necrophyte
09-08-2016, 08:22 PM
Creating a form inside the php module.+
The form calls itself.+
Quick little snippet example

global $vbulletin;
if (!empty($_POST['sbutton'])){
Do some stuff, but we can't userid = 0 $vbulletin->userinfo['userid'] and even vB::getCurrentSession()->get('userid') returns 0
}else{
<form class='block' action='/forum/SituationReport' method='post' id='sitrep' name='sitrep'>
<input type='submit' class='button' name='sbutton' id='_save' value='Submit'>
}


On the submit. The session is lost.
I tried adding the normal loading scripts but I get
Couldn't read config file config.php
Which is typical if its already loaded (Or at least in my experience)
What else am I missing here. Script works outside of vbulletin as an external page.

--------------- Added 1473374738 at 1473374738 ---------------

@#%#@$%
Figure out cause I was calling ./global.php
I missed that.

Replicant
09-08-2016, 10:29 PM
For a simple form submission, I wouldn't bother with a PHP module. Most all the user data you need to work with is in the JS pageData array and whatever is not is easy enough to pull with an ajax call. Not sure what you're working on, but JS for forms is easy and can usually be as sophisticated as you need it to be.

Necrophyte
09-09-2016, 06:33 PM
I wish my JS was decent. I barely scrape by using JS. I can do basic stuff like form validation, and manipulating variables. But other than that.
Was just a quick little Site Rep form that would post to the forum.

noypiscripter
09-10-2016, 02:42 AM
You don't have to read or load config.php file or any file for that matter. What is exactly do you want to accomplish?

You can get all of the public vbulletin options by doing this:

$vboptions = vB5_Template_Options::instance()->getOptions();
$vboptions = $vboptions['options'];
var_dump($vboptions);

Necrophyte
09-10-2016, 01:25 PM
Hey Glenn,

So I run the forums of a gaming community. In Milsim style we have a sit rep report. If someone does something good, or something bad there is a report someone can fill out and only certain people can see it in the forums. All the posting and stuff I have working (Thank you). So I was creating the form in a php module. I have a link on the submenu that calls it.
However, I was so used to calling ./global.php from vb4 days I did it instinctively.
What I found out is. When you do call ./global.php. It actually kills the user session.
$vbulletin->userinfo['userid'] would = 0. I was losing my mind cause I was sure I fixed the posting code but it came up with no permissions. Well that was because it was having the userid, and session removed.
All I had to do was remove the ./global.php include and everything worked. But I'm finding the more I post in here after I can't figure it out, its usually a few min later I figure it out on my own.

Replicant
09-10-2016, 11:57 PM
I have not having done any php coding in vb4 but after looking at it, there looks to be far more effort required for a vb4 mod vs vb5. Am I crazy? probably, but that just what ity looks like to me.

Paul M
09-11-2016, 12:55 PM
Yep, you're crazy :)