Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 8 Years, 10 Months, 4 Weeks ago [PHP] Can't able to get uid with $mybb
#1
Solved: 8 Years, 10 Months, 4 Weeks ago
Why I can't get $mybb variable in function ?
<?
define("IN_MYBB", 1);
require "../global.php";

global $mybb;
function getid()
{
$userid=$mybb->user[uid];
return $userid;
}

echo getid();

?>
www.vubscs.com ( A new way of Mybb)
#2
Solved: 8 Years, 10 Months, 4 Weeks ago
This user has been denied support. This user has been denied support.
Try to define global $mybb inside the function.

Also, it's

$mybb->user['uid']

and not $mybb->user[uid] (you missed single quotes).
#3
Solved: 8 Years, 10 Months, 4 Weeks ago
(2012-11-18, 06:46 PM)crazy4cs Wrote: Try to define global $mybb inside the function.

Also, it's

$mybb->user['uid']

and not $mybb->user[uid] (you missed single quotes).

It works but why the Global works if we define it out side of our every function ?
www.vubscs.com ( A new way of Mybb)
#4
Solved: 8 Years, 10 Months, 4 Weeks ago
This user has been denied support. This user has been denied support.
You're requiring global.php already, which has mybb defined (it requests from inc/init.php where $mybb variable's formation starts) hence it works.

But when function comes, it does not use the file (here, global.php as it's outside the function) and hence we have to define $mybb in globals for it to get work there.
#5
Solved: 8 Years, 10 Months, 4 Weeks ago
oahky Smile
www.vubscs.com ( A new way of Mybb)
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)