Xampp localhost - Error!: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) [closed] - xampp

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I'm trying to load my htdocs/pdoexample/index.php
<?php
$host = 'localhost';
$user = 'root';
$password = '123456';
$dbname = 'pdoposts';
// Set DSN (Data Source Name)
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
// Creat a PDO instance
try {
$dsn = "mysql:dbname={$dbname};host={$host}";
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
// # PDO QUERY
$stmt = $pdo->query('SELECT * FROM posts');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo $row['title']. '<br>';
}
?>
to see the error, and ran http://localhost/pdoexample/, I got this error below.
Error!: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
UPDATE / SOLUTION --> I found out that i did not set any database password so I changed "$password = '123456';" to "$password = '';"

Related

Secure FTP file download

I'm trying to download the most recent file with the extension add.zip via ftp
I'll preface this by saying I am not well versed in php and have created this frankenstein piece of code from a scattering of other codes.
here is my code
<?php
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
if (!$login_result) {
// PHP will already have raised an E_WARNING level message in this case
die("can't login");
}
// get list of files on given path
$files = ftp_nlist($ftp, '/1668161919_DATA/*add.zip') or die("Could not find file");
$mostRecent = array(
'time' => 0,
'file' => null
);
foreach ($files as $file) {
// get the last modified time for the file
$time = ftp_mdtm($ftp, $file);
if ($time > $mostRecent['time']) {
// this file is the most recent so far
$mostRecent['time'] = $time;
$mostRecent['file'] = $file;
}
}
ftp_get($ftp, "/home/mysite/public_html/wp-content/uploads/data-zipped/target.zip", $mostRecent['file'], FTP_BINARY);
ftp_delete($ftp, $mostRecent['file']);
ftp_close($ftp);
?>
After some testing
<?php
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
if ($login_result === TRUE) {
echo 'woot!';
} else {
echo 'doh!';
}
Returns a woot
but
// set up basic ssl connection
$ftp = ftp_ssl_connect('myremotesite.com');
// login with username and password
$login_result = ftp_login($ftp, 'username', 'password');
// get list of files on given path
$files = ftp_nlist($ftp, '/1668161919_DATA/*add.zip');
if ($files === TRUE) {
echo 'files found!';
} else {
echo 'doh! files not found';
}
?>
Cause a 504 error with no further information.
What am I doing wrong?
When I copy the URL to clipboard in FileZilla the data is sftp://username#myremotesite.com/1668161919_DATA
Am I even close to getting this right?
When I have tried using similar FTP file downloads in the past, it was with
ftp_connect
This is the first time I have been forced to use
ftp_ssl_connect
Ok, so I set up a testing environment and ran the script using ftp_connect instead of ftp_ssl_connect and the code worked fine.
I think I need to define my port as 22. But
$ftp = ftp_ssl_connect('myremotesite.com','22')
doesn't work. Can anyone assist?

send data using controller in app.blade laravel 4 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a UserController and i want to send data from UserController function to app.blade.php.
function sessionUser(){
$data['status'] = Auth::user()->status;
$data['id'] = Auth::id();
$data['values]=DB::table('user_permission)->get();
return view('app.blade', compact('data'));
}
and in app.blade.php
dd($data);
Try it:
function sessionUser(){
$data['status'] = Auth::user()->status;
$data['id'] = Auth::id();
$data['values']=DB::table('user_permission')->get();
return view('app')->with($data);
}
Or
function sessionUser(){
$status = Auth::user()->status;
$id = Auth::id();
$values = DB::table('user_permission')->get();
return view('app', compact('status','id','values'));
}
Then echo dd($status);

Codeigniter session work fine on local but not working on Godaddy [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I developed website on php framework (Codeigniter) that working fine on my local (WAMP Server). When I upload it to Godaddy hosting, it unable to login into website. Below is the login class function.
public function index()
{
if ($this->session->userdata('admin_login') == 1)
redirect(base_url() . 'index.php?admin/dashboard', 'refresh');
$this->load->view('backend/login');
}
function ajax()
{
$response = array();
$email = $_POST["email"];
$password = $_POST["password"];
$response['submitted_data'] = $_POST;
$login_status = $this->validate_login( $email , sha1($password) );
$response['login_status'] = $login_status;
if ($login_status == 'success') {
$response['redirect_url'] = '';
}
echo json_encode($response);
}
function validate_login($email = '' , $password = '')
{
$credential = array( 'email' => $email , 'password' => $password );
$query = $this->db->get_where('users' , $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$this->session->set_userdata('admin_login', '1');
$this->session->set_userdata('admin_id', $row->id);
$this->session->set_userdata('name', $row->name);
$this->session->set_userdata('login_type', 'admin');
return 'success';
}
return 'invalid';
}
I realize that $this->session->set_userdata() method is not working on godaddy.
Please try this
Please add session library just like below.
$this->load->library('session');
if ($this->session->userdata('admin_login') == 1)
redirect(base_url() . 'index.php?admin/dashboard', 'refresh');
$this->load->view('backend/login');
First Load Session Library
then
Instead of Using this
if ($this->session->userdata('admin_login') == 1)
Use This
if ($this->session->userdata['admin_login'] == 1)
Check if it is working or not
Try a few alternatives may work:
Change these lines in application/config/config.php
$config['sess_cookie_name'] = 'cisession'; //remove(underscore)
$config['cookie_domain'] = ".example.com"; //make it site wide valid
You can store multiple session variable in array
function validate_login($email = '', $password = '') {
$credential = array('email' => $email, 'password' => $password);
$query = $this->db->get_where('users', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$sess_array = array(
'admin_login' => 1,
'admin_id' => $row->id,
'name', $row->name,
'login_type', 'admin'
);
$this->session->set_userdata('logged_in', $sess_array);
}
return 'invalid';
}
You need to upload session library in your constructor
public function __construct()
{
parent::__construct(); /* necessary! */
/* load model for calls to database */
$this->load->library('session');// load session library
$this->load->helper('url');
}
In your index you have to check user logged_in is set or not
public function index()
{
if ($this->session->userdata('logged_in')){// check session set or not
redirect(base_url() . 'index.php?admin/dashboard', 'refresh');
$this->load->view('backend/login');
}
}
OK, i assume you're using CI2, as you're getting FALSE on a non-existing session var. CI sessions use cookies and / or a database, depending on your config. what are the cookie settings on your config file?
you should pay attention to these settings:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
and these ones (default config shown on both cases):
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
is your site hosted on a subdomain? cookies are set via headers. is there any output being generated before your cookies are set? set up your log_threshold to 2 so you can see eventual errors and debug messages being generated.
$config['log_threshold'] = 2;
did you set up an encription key?
$config['encryption_key'] = '[there-must-be-something-here]';
I tried all answers that mention here, but not work for my issue.
My issue is
$this->session->userdata('admin_login') returns false.
Finaly I tried database to store session.
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
And created ci_sessions table.
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
Then it works fine
This should be Your Config Configuration
$config['sess_cookie_name'] = 'cisession';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
Also In your Model You must set the session.
public function login ()
{
$user = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->hash($this->input->post('password')),
), TRUE);
if (count($user)) {
// Log in user
$data = array(
'name' => $user->name,
'email' => $user->email,
'gender'=>$user->gender,
'user_num'=>$user->user_num,
'id' => $user->id,
'loggedin' => TRUE,
'balance' =>$user->balance,
'usertype' =>'admin',
);
$this->session->set_userdata($data);
}
}
this Works for me :)

parameter mismatch,pattern is a string while replacement is an array

Trying to resend login details to a user through his mail.what I want to do is after the user has click on the forgotten password link, a form is displayed requesting for his email to be posted.after the email has been posted, I check if the email corresponds to an email in the users table and send details.
Here's my controller:
public function postResendPassword()
{
$posted = Input::get();
$email = $posted['email'];
$user = User::where('email', '=', $email)->first();
$user_password= $user->password_confirmation;
$user_username = $user->username;
$user_email = $user->email;
$to = $user->email;
$subject = " login details request";
$message =
<h3>login details</h3>
email : $user_email
login password : $user_password
regards;
mail($to, $subject, $message);
}
how do I go about this and fix this error

codeigniter active record where, or_where?

I am using Active Record on CodeIgniter. I am confused on which approach I should take. Currently, our login system let's the user to use username/email for the login along with the password. But my current active record, seems to let the user logged in if he choose to use the email + no password.
Right now this is my query:
$this->db->select('id,level,email,username');
$this->db->where('email',$user);
$this->db->or_where('username',$user);
$this->db->where('password',$pass);
$query = $this->db->get('users');
if($query->num_rows>0)
return TRUE;
else
return FALSE;
Sample inputs:
Username: test | Password: pass | Result: Success
Username: test | Password: empty | Result: Failed
Username: test#domain.com | Password: pass | Result: Success
Username: test#domain.com | Password: empty | Result: Success
The fourth test input must be Failed in result, but it seems that it logs the user even if the password is empty.
The issue is probably that you need to add brackets when mixing AND’s and OR’s in a WHERE clause. Try this:
$this->db->select('id,level,email,username');
$this->db->where("(email = '$user' OR username = '$user')
AND password = '$pass'");
$query = $this->db->get('users');
#RidIculous is right. This is a correct way to do it:
$user = $this->db->escape($user);
$this->db->select('id,level,email,username');
$this->db->where("(email = $user OR username = $user)");
$this->db->where('password', $pass);
$query = $this->db->get('users');
Or a format I prefer (PHP 5+)
$user = $this->db->escape($user);
$query = $this->db
->select('id,level,email,username')
->where("(email = $user OR username = $user)")
->where('password', $pass)
->get('users');
$conditions = '(`username`="'.$username.'" OR `email`="'.$email.' OR `mobile`="'.$mobile.'"') AND `password`="'.$password.'"';
$query = $this->db->get_where('table_name', $conditions);
$result = $query->result();

Resources