I use this code:
$usuario=getJoomUser();
$username=strtolower($usuario['username']);
$name=$usuario['name'];
if ($usuario['id']== 0)
{
echo "$name";
print "No estas logueado en el sistema";
}
else
{
The code works fine but not with some computers. Joomla load fine the user and his password but not my code in PHP. However, if I use that information in other computers works fine.
Any ideas?
Thanks a lot.
My function is:
function getJoomUser() {
error_reporting(1);
define( '_JEXEC', 1 );
define( 'DS', '/' );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] . DS . 'Joomla3.2.3' );
if(is_file(JPATH_BASE .DS.'configuration.php')) {
require_once(JPATH_BASE .DS.'configuration.php');
} else {
echo "Could not locate configuration.php <br />";
}
if(is_file(JPATH_BASE .DS.'includes/defines.php')) {
require_once(JPATH_BASE .DS.'includes'.DS.'defines.php');
} else {
echo "Could not locate defines.php <br />";
}
if(is_file(JPATH_BASE .DS.'includes/framework.php')) {
require_once(JPATH_BASE .DS.'includes'.DS.'framework.php');
} else {
echo "Could not locate framework.php<br />";
}
if(is_file(JPATH_BASE .DS.'libraries/joomla/factory.php')) {
require_once(JPATH_BASE .DS.'libraries/joomla/factory.php');
} else {
echo "Could not locate factory.php<br />";
}
$mainframe = JFactory::getApplication('site');
$user = JFactory::getUser();
$userData['username'] = $user->username;
$userData['name'] = $user->name;
$userData['id'] = $user->id;
$userData['email'] = $user->email;
$userData['groups'] = $user->groups;
return $userData;
}
?>
I have tried with the option -->guest and the problem continues. The key is: That happens in some pcs and I try to sign in with these user's data in my computer or another computer works fine.
I tried without to call a function and remains the same.
I don't know where you got getJoomUser from but to get the user object, you need to use this:
$user = JFactory::getUser();
You can then do what you wish like so:
if ($user['id'] == 0){
print "No estas logueado en el sistema";
}
else{
echo $user->username;
}
I have update to 3.3.6 and the problem continues.
On Internet Explorer, activating compatibility view works fine. WRONG
I will change to drupal...
Thanks
Related
I have completed a website in codeigniter. The login page is working in localhost but when I am uploading the same onto the server, the login page is not working. It is showing a blank white page.
$this->load->model("studentsmodel");
$result = $this->studentsmodel->loginCheck($post_data);
if (!$result) {
$this->notifications->notify('Wrong username or password; Login Failed', 'error');
redirect('site/login', 'refresh');
}
else {
$this->session->set_userdata('student_id', $result['id']);
$this->session->set_userdata('stud_cin', $result['stud_cin']);
$this->session->set_userdata('stud_path', $result['stud_path']);
redirect('student/id/'.$this->session->userdata('student_id'), 'refresh');
}
This is the code for login page in codeigniter. If there is no value in $result, the notification "wrong username/password" is not working. Also if there is data inside $result , it is not going to else part. In both the cases it is showing a white blank page. Can anyone suggest a solution for this ? I am using CI 2.1. This all is working properly in the localhost but not in the server. Any problm with refresh being used with redirect().
output of $result is
Array
(
[id] => 2
[stud_cin] => 11AK11
[stud_path] => photo/no-photo.JPG
)
Try the below code:
$this->load->model("studentsmodel");
$result = $this->studentsmodel->loginCheck($post_data);
if($result) {
$id = $this->session->set_userdata('student_id', $result['id']);
$stud_cin = $this->session->set_userdata('stud_cin', $result['stud_cin']);
$stud_path = $this->session->set_userdata('stud_path', $result['stud_path']);
redirect('student/id/'.$id);
}else{
// $this->notifications->notify('Wrong username or password; Login Failed', 'error');
redirect('site/login');
}
Try this
$this->load->model("studentsmodel");
$result = $this->studentsmodel->loginCheck($post_data);
if($result) {
if(isset($result['id']) && $result['id'] !== ''){
$this->session->set_userdata(array(
'student_id'=>$result['id'],
'stud_cin'=>$result['stud_cin'],
'stud_path'=>$result['stud_path']
));
redirect('student/id/'.$result['id'], 'refresh');
}
else{
redirect('site/login', 'refresh');
}
}
else {
redirect('site/login', 'refresh');
}
file upload directory not created in my vps its show me blank page in error massege
Here is my code.
$dir_exist = true; // flag for checking the directory exist or not
if (!is_dir('./assets/uploads/profile_pictures/' . $id))
{
mkdir('./assets/uploads/profile_pictures/' . $id, 0777, true);
$dir_exist = false; // dir not exist
}
if ( ! $this->upload->do_upload('upload_profile_picture'))
{
if(!$dir_exist)
rmdir('./assets/uploads/profile_pictures/' . $id);
$error = array('error' => $this->upload->display_errors());
//$this->session->set_flashdata('error', $error[1]);
print_r($error);
}
else
{
$upload_data = $this->upload->data();
$new_name=$upload_data['file_name'];
//$this->session->set_flashdata('error', $data[1]);
}
if($new_name=='0'){
$new_name=$temp_profile_pic;
}
$date = str_replace( ':', '', $date);
if (!is_dir('uploads/'.$date)) {
mkdir('./uploads/' . $date, 0777, TRUE);
}
Please try above code and check if this code is working then definately the issue is different.
and check the id is not getting : either it will never created new dir.
Here is the reference: https://www.socketloop.com/tutorials/codeigniter-php-create-directory-if-does-not-exist-example
I'm trying to modify the
'Token Interceptor' system plugin
by joomunited.com
The original plugin redirects on encountering an invalid token error using register_shutdown_function.
I'm trying to get it to:
Log the user out if they are logged in
Redirect to the login page with the invalid token message
Code:
$app = JFactory::getApplication();
if (!JFactory::getUser()->guest)
{
$app->logout();
}
$app->redirect('/index.php', JText::_('JINVALID_TOKEN'), 'warning');
I can successfully log the user out and redirect to the login page but the error message is not being displayed.
How can I retain the message after logging the user out?
i've also tried:
$app->enqueueMessage(JText::_('JINVALID_TOKEN'), 'warning');
but that didn't work either...
The solution I came up with was a variation of Alonzo Turner's 2nd post here.
The plugin redirects to the login page with a parameter passed in the url. The onAfterInitialise event then looks for this parameter and displays a message if it's found.
class PlgSystemTokeninterceptor extends JPlugin
{
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config);
$app = JFactory::getApplication();
if (($app->isSite() && $this->params->get('use_frontend')) || ($app->isAdmin() && $this->params->get('use_backend')))
{
register_shutdown_function(array($this,'redirectToLogin'));
}
}
public function redirectToLogin()
{
$content = ob_get_contents();
if($content == JText::_('JINVALID_TOKEN') || $content == 'Invalid Token')
{
$app = JFactory::getApplication();
if (!JFactory::getUser()->guest)
{
$app->logout();
}
$app->redirect(JURI::base().'index.php?invalid_token=true');
return false;
}
}
function onAfterInitialise()
{
$app = JFactory::getApplication();
$invalid_token = $app->input->get('invalid_token', 'false');
if ($invalid_token == 'true')
{
$app->enqueueMessage(JText::_('JINVALID_TOKEN'), 'warning');
}
return true;
}
}
When you logout you destroy the session so you are not going to have the message any more.
This will get you a message on redirect.
$this->redirect = JUri::base() . 'index.php?option=com_users&view=login';
if (!JFactory::getUser()->guest && $app->input->getCmd('option') != 'com_users')
{
$app->enqueueMessage('message', 'warning');
//$app->logout();
$app->redirect($this->redirect);
}
This will not because the session is destroyed
$this->redirect = JUri::base() . 'index.php?option=com_users&view=login';
if (!JFactory::getUser()->guest && $app->input->getCmd('option') != 'com_users')
{
$app->enqueueMessage('message', 'warning');
$app->logout();
$app->redirect($this->redirect);
}
Not tested but
$app->logout()
echo '<div class="">'. JText::_('whatever you want') . '</div>';
$module = JModuleHelper::getModule('login');
$output = JModuleHelper::renderModule($module);
Something like that
Hi im trying to check if a file exist on a remote server and then save the url path to the file in a attribute on the product in magento.
This is how far i have got . i use some code from another function i have that imports images to my magento store. But i have never tested to only get the url path .
<?php
ini_set('display_errors', 1);
require_once('app/Mage.php');
Mage::app();
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$url = "http://www.imonline.se/media42/trailers/199151abe/swinks/hkmedia/";
foreach($_productCollection as $product)
{
//if(file_exists($serverurl))
{
$thispro = Mage::getModel('catalog/product')->load($product->getId());
$attributeValue = $thispro->getFaktaId();
$imgupdate = $thispro->getImgupdate();
if($thispro->getFaktaId()=="" || $thispro->getImage()=="no_selection")
{
if($attributeValue != "")
{
copy($url.$attributeValue );
$im = $attributeValue.".mp4";
if(file_exists)
{
$product->setFilmUrl($url.$im);
$product->save();
}
}
}
}
}
?>
file_exists - Checks whether a file or directory exists
To Check if Remote File Exists using PHP
$url = $url.$im;
$exist = file_exists_remote($url);
if($exist) {
echo 'File Exists';
$product->setFileUrl($url.$im);
$product->save();
} else {
echo 'File not found';
}
I have been dealing with a problem for a while. How can I set the validation errors using redirect in a function? This is the code I have in my controller :
function send()
{
$this->form_validation->set_rules('e-mail', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('cellphone', 'Cellphone Number', 'trim|required|is_natural');
$this->form_validation->set_message('required', '%s is required.');
$this->form_validation->set_message('valid_email', '%s is not a valid Email Address');
$this->form_validation->set_message('is_natural', '%s can only contain numbers.');
$this->form_validation->set_error_delimiters('<li>', '</li>');
if($this->form_validation->run() == FALSE)
{
redirect ('/');
}
else
{
echo '<pre>';
print_r($_POST);
echo '<pre>';
}
}
And this is the code I use in my view file:
<? if (validation_errors())
{
echo '<div id="validation_errors" title="Error:">';
echo '<div class="response-msgs errors ui-corner-all"><span>Errors:</span><br /><ul>';
echo validation_errors();
echo '</ul></div>';
echo '</div>';
}
?>
I found the way to do it. Redirecting does not keep the data to be shown. I used the code below to solve the problem:
if($this->form_validation->run() == FALSE)
{
$this->index();
}
I know it's a bit late but this method works wonders for me.
If you are validating your form in a different function than the one the form is loaded in, you can send your validation_errors() to any page that you redirect() by passing the validation_errors() method to $this->session->set_flashdata() like so:
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('error', validation_errors());
redirect('/');
}
In your controller functions where you would like your errors or messages to be received you can then set them to the $data array like so:
if (!empty($this->session->flashdata('message'))) {
$data['message'] = $this->session->flashdata('message');
} elseif (!empty($this->session->flashdata('error'))) {
$data['error'] = $this->session->flashdata('error');
}
At the top of my views I usually include:
<?php if (isset($message)) {
echo '<p class="alert alert-info">'.$message.'</p>';
} elseif (isset($error)) {
echo '<p class="alert alert-danger"><strong>Error: </strong>'.$error.'</p>';
}?>
Using twitter bootstrap classes to format the messages helps to differentiate them.
I included the message flashdata so that you can see how whatever type of message or error you want to send, you are able to format them differently for all information, warning, success and error messages.
As per my comment:
function index()
{
$this->load->library('form_validation');
$data = array
(
'Param' => 'Value'
);
if($this->input->post('cellphone', true) !== false)
{
if($this->form_validation->run() != FALSE)
{
echo '<pre>' . print_r($_POST, true) . '</pre>';
}
}
$this->load->view('index', $data);
}
First, you need to change your form so it points to the current page, i.e. current_url() or site_url('controller/index').
When you go to the index without posting, it will simply skip the validation. Upon submitting your form, it will run the validation.
You can then use the built in form_error or validation_errors methods to display the errors within your index view.
finally i got a solution for the redirect with validation_errors
This is using to pass the validation_errors in the session data,
i do it like this
if ($this->form_validation->run()) {
$data = array(
'email' => $this->input->post('email'),
'is_login' => true
);
$this->session->set_userdata($data);
redirect($this->input->post('redirect'));
}
else
{
$data = array (
'errors' => validation_errors(),
'is_login' => false
);
$this->session->set_userdata($data);
redirect($this->input->post('redirect'));
}
and in the page i used
$this->session->set_flashdata('redirectToCurrent', current_url());
if ($this->session->userdata('is_login'))
{
echo "You are using this as : </br>" . $this->session->userdata('email');
echo "</br><a href='/logout'>Logout</a>";
}
else
{
echo form_open('login');
echo "" . $this->session->userdata('errors');
echo "email : " . form_input('email');
echo "Password : " . form_password('password');
echo form_submit('submit', 'Login');
echo form_hidden('redirect',$this->uri->uri_string());
echo form_close();
}
I wish you like this fast solution