I am reading a extension file, and see below codes:
if ($job && $job['cruser_id'] != $GLOBALS['TSFE']->fe_user->user['uid'])
I find out $GLOBALS['TSFE']->fe_user is the object of class:tslib_feuserauth, i checked the file: class.tslib_feuserauth.php,
my question is :
what is user['uid']? user is an array, but in class.tslib_feuserauth.php did not see such codes like: $this->user['uid']
If user is logged this array represents user's row from DB and just contains all columns of fe_users table otherwise it's FALSE, so you can use it to determine the login state:
if ($GLOBALS['TSFE']->fe_user->user){
$msg = 'You are logged as ' . $GLOBALS['TSFE']->fe_user->user['username'];
} else {
$msg = 'You need to login first';
}
Related
I want my website and my mybb board to be connected. I Googled and made the integration, and I'm able to get a username id, as long as I specify their ID, but nothing happens when I'm using the function as explained.
What I'm trying to do is verify a connection of one to the forums, via my website, and then show their name.
Here's my code, as well as my attempts to get a username:
PHP Code:
define('IN_MYBB', NULL);
require_once 'forums/global.php';
require_once 'forums/class.MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$user = get_user($uid);
while ($forum_user = mysqli_fetch_array($user))
{
echo $forum_user['username'];
}
You could use:
define('IN_MYBB', NULL);
require_once 'forums/global.php';
if(isset($mybb->user['uid'])){
echo "User Found: ".$mybb->user['usernmae']."($mybb->user['uid'].")";
} else {
echo "No user found";
}
MyBBIntegrator isn't even required. But the above code will check if the user is logged in, and display the username and userid. If not it will display No User Found. Hopefully this helps.
I'm a novice in server-side programming so any advice is appreciated.
I have some PHP files uploaded on a virtual server (000webhost.com) and I'm having trouble with locating a file I'm requiring in another PHP file. The register.php is attempting to "require_once" the update_user_info.php
Here's the code for register.php (Which I've taken from a tutorial and adjusted it with my variables):
<?php
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'../update_user_info.php');
$db = new update_user_info();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST ['password']) && isset($_POST['branch']) && isset($_POST['gender'])) {
// receiving the post params
$username = $_POST['username'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$branch = $_POST['branch'];
$gender = $_POST['gender'];
// check if user is already existed with the same email
if ($db->CheckExistingUser($email)) {
// user already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
// create a new user
$user = $db->StoreUserInfo($username, $name, $email, $password, $branch, $gender);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["user"]["username"] = $user["username"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["branch"] = $user["branch"];
$response["user"]["gender"] = $user["gender"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameter (username, name, email or password) is missing!";
echo json_encode($response);
}
?>
And here's a screenshot of the error that's occurring when attempting to visit the link containing the register.php:
Screenshot of the error
What I've tried so far:
1- tried to use require_once __DIR__."/../filename.php"; and lots more of the same, basically tinkering the statement with different language constructs and constants.
2-Read tutorials on the correct way to use require once but their cases is almost always very different. Either they are using WAMP/XAMPP -meaning they have a local path not a virtual one- So no luck there.
3- tried to change .htaccess file, as someone said in a post that it solved his problem.
4- I'm certain that both files are uploaded to the same directory. Yet it says "No such file".
Does anyone have an idea of where the error could be stemming from? Thanks in advance!
I'm having some trouble with a block of code I'm trying to implement.
My thought process was to have different users with different attributes in the "userType" (which is an INT type) column in my database and to have a switch case to take the result of the query and select which page to redirect to. The links for re-direction haven't been inserted yet as the login switch case isn't working.
Here is the code for my "loginsuccess.php"
<?php
session_start(); // Right at the top of your script
?>
<?php
ob_start();
$host="localhost"; // Host name
$username="google_test"; // Mysql username
$password="password"; // Mysql password
$db_name="google_test"; // Database name
$tbl_name="user"; // Table name
$mysqli = new mysqli($host, $username, $password, $db_name);
if($_SESSION['$myusername']==true)
{
$sessionUsername = $_SESSION['$myusername'];
$userType = "SELECT userType FROM '$tbl_name' WHERE username='$sessionUsername'";
$result = mysqli_query($mysqli, $userType);
switch ($result){
case "1":
//userType 1 is admin
echo $_SESSION['$myusername'];
echo ", Login Successful. Welcome Admin.";
break;
case "2":
//userType 2 is business
echo $_SESSION['$myusername'];
echo ", Login Successful. Welcome to your business page.";
break;
case "3":
//userType 3 is general user
echo $_SESSION['$myusername'];
echo ", Login Successful. Welcome to the Fun Finder App!!.";
break;
default:
echo $_SESSION['$myusername'];
echo ", it appears that your user type has not been defined yet.";
echo " Please contact support to resolve this issue.";
}
}
elseif($_SESSION['$myusername']==false)
{
echo "oops......";
//echo '<span>Login/Register</span></li>';
}
ob_end_flush();
?>
My login script is working and passes the username and password through the database successfully via another php page. The result I'm getting from this php file is that the switch case goes directly to the default case regardless of which login I use. I'm assuming it is something to do with my query not returning the proper result as I tried to echo the $result variable and got nothing. Php is not my strongest language so any help would be appreciated. Thanks in advance!
Mysqli_query returns a result object and not the actual value. You can read the value from that object however:
http://php.net/manual/en/mysqli.query.php
As an additional hint: it might make sense to store these user privileges along with the user login name in the session once the user succesfully authenticates. (There might be more places where this info is needed - that way you don't need to do queries all the time)
The only drawback is that this will not respond to permission chamgesnfor that user (when a user becomes admin he will need to login again)
In my opinion you must use mysql_fetch_array() to store the result from the database before using it in a switch case.
example:
$row=mysql_fetch_array($result);
$privilege=$row['usertype']; //user type is from the column in your table
So one of my pages consists of a quiz form that has several questions of type multiple choice, the choices are specified as radio buttons. I have been scanning the Symfony documentation to find out how to access form field values inputted by the user. Thing is, this isn;t a doctrine or propel based form, and neither do I require the values to be stored in the database, hence executing a $form->save() makes little sense to me. But I do require access to specific values of my form in my backend once the user hits submit.
Most of Symfony documentation that i have run into doesn't necessarily explain how this can be done. I would assume it would be something to the effect of :
$request->getParameter( 'radio_choices_id selected value ').
Thanks to all who read this and Cheers to the ones who respond to it :)
Parijat
Hm, it is very simple if I understand your question right)
For widget:
$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' => array('ch_1', 'ch_2')));
Ok,in action:
$this->form = new FaqContactForm();
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter($this->form->getName()));
if ($this->form->isValid()) {
$your_val=$this->form->getValue('name');
//or
$your_val=$this->form['name']->getValue());
}
}
In backend in protected function processForm(sfWebRequest $request, sfForm $form)
you have
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
$notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
try {
$product = $form->save();
} catch (Doctrine_Validator_Exception $e) {
$errorStack = $form->getObject()->getErrorStack();
$message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
foreach ($errorStack as $field => $errors) {
$message .= "$field (" . implode(", ", $errors) . "), ";
}
$message = trim($message, ', ');
$this->getUser()->setFlash('error', $message);
return sfView::SUCCESS;
}
Before $product = $form->save(); try
$your_val=$form->getValue('name');
//or
$your_val=$form['name']->getValue());
I want to check the user table for status=1 as extra validation. My getAuthAdapter() method looks like this:
private function getAuthAdapter (){
$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
$authAdapter->setTableName('vi_users')
->setIdentityColumn('email')
->setCredentialColumn('password');
return $authAdapter;
}
How would I alter this to include the extra validation?
I ran across this problem myself, and I'm not sure it is possible to check another column at the sametime. So I do it straight aftwerwards, with something like this:
$auth = Zend_Auth::getInstance();
....
if (process($form->getValues())) {
// login credentials are correct, so we now need to check if their account is activated
if ($auth->getIdentity()->active != 1) {
// if not, log them out and tell them to activate
Zend_Auth::getInstance()->clearIdentity();
$output .= "Your account has not yet been activated, please check your email (including spam bin) for the activation link.";
} else {
// if they're active then login is successful
$output .= "You are now logged in";
}
} else {
// username/password wrong
$output .= "Credentials invalid";
}
Update: Given Orlando's answer, it looks like what you've asked for originally is possible. You could use my solution though if you would like to distinguish between status value being 'wrong' and user/pass being wrong.
You could do something like:
$adapter = new Zend_Auth_Adapter_DbTable(
$db,
'users',
'username',
'password',
'MD5(?) AND status = 1'
);
where $db would be Zend_Db_Table::getDefaultAdapter()
Taken from http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html