I am moving what looks like a pretty simple php/MSQL app from a Windows IIS server to a Cpanel/ Apache server. The app works fine on existing IIS/MySQL server using this format to connect:
<?php
class Connection {
var $conn;
var $user = 'XX0000XX_XXadmXX';
var $pass = 'XXXpasswordXXXX';
var $dbname = 'XXckbXXX_XXX13XX';
var $host = '74.0.0.0';
function Connection() {
$this->conn = mysql_connect($this->host, $this->user, $this->pass);
mysql_select_db($this->dbname,$this->conn) or die( "db-connect". mysql_error());
}
function closedb() {
//mysql_close(($this->host, $this->user, $this->pass ) or die( "db-close". mysql_error() );
mysql_close($this->conn)or die( "db-close". mysql_error() );
}
}
?>
I imported the DB into CPANEL/MySQL using PhpMyAdmin. 1st test failed due to $host not accepting IP address value. After changing IP to localhost - tested the connection with a DB connection script and that passed. The error is that at I can connect with the same username and PW as Windows server. But after logging in any link I click in the admin kicks me out.
Any clues would be helpful - let me know if I can provide any information that would help. I am thinking that there may be a windows specific change that needs to happen or something to do with the the DB host.
Here are some values in a settings file - before the Ip addresses were set with domain name - set with IP to test:
define('ADMIN_MANAGEMENT', "sitename");
define('FROM_NAME', "Admin");
define('SITE', "sitename");
define('SITE_NAME', "http://74.0.0.0/");
define('ADMIN_ID', "dwayne#fair.com");
define('KEYWORD', "sitename");
define('SITE_URL',"http://74.0.0.0/");
define('SITEIMGPATH', "http://74.0.0.0/public/images/");
define('ITEMS_PER_PAGE', "15");
define('PRODUCTS_PER_PAGE', "5");
define('UPLOAD_FILES', "uploads/files/");
define('UPLOAD_IMAGES', "uploads/images/");
define('SMALL_IMAGE_WIDTH',190);
define('SMALL_IMAGE_HEIGHT',77);
define('PROFILENAME', "Welcome to domain.com");
define('CARID',1000);
define('RESIZE_IMAGE_WIDTH',400);
define('RESIZE_IMAGE_HEIGHT',300);
/*Live path*/
define("ROOT", "http://" . $_SERVER["SERVER_NAME"] . "/admin/");
define("ROOTS", "http://" . $_SERVER["SERVER_NAME"] . "/admin/");
Related
I have developed an project for News application and I have both Dashboard and Android Application ready!
Now, I have to host my server side code (Dashboard) on hosting website. I chose 000webhost for testing purposes and hosted on that. I am able to fetch the data in app and able to post from dashboard when hosted on 000webhost, but when I have chose another services like BlueHost, InfinityFree then I am unable to fetch the data in my application!
Now the problem is-
Since I have developed my application using local servers so my config.php look likes this
<?php
//database configuration
$host = "localhost";
$user = "epiz_24504438";
$pass = "******";
$database = "epiz_24504438_myapp_db";
$connect = new mysqli($host, $user, $pass, $database);
if (!$connect) {
die ("connection failed: " . mysqli_connect_error());
} else {
$connect->set_charset('utf8');
}
$GLOBALS['config'] = $connect;
$ENABLE_RTL_MODE = 'false';
?>
But when I have to upload it on hosting services websites the have a forced SQL host-name like
<?php
//database configuration
$host = "sql211.epizy.com";
$user = "epiz_24504438";
$pass = "******";
$database = "epiz_24504438_myapp_db";
$connect = new mysqli($host, $user, $pass, $database);
if (!$connect) {
die ("connection failed: " . mysqli_connect_error());
} else {
$connect->set_charset('utf8');
}
$GLOBALS['config'] = $connect;
$ENABLE_RTL_MODE = 'false';
?>
Due to sql211.epizy.com I am able to access my Dashboard(no data in application) and when I am changing it to localhost then I am not able to access both dashboard and data in application.
While on 000webhost they have SQL host as locahost so it working fine there on both application and dashboard but due to limitations of free hosting I don't want to use it!
So please help me out!! What should I do?
$connect = new PDO(('mysql:host= ;dbname= ', ' ', ' ');
Example:
$connect = new PDO(('mysql:host= hosturl;dbname= ', 'user', 'password');
I am trying to upload a file from my machine (client side) to the FileZilla server (server side) I have for storing the web page files.
When trying to connect to FileZilla through PHP I receive the following error message:
Connection failed: Connection refused
Usually, I would expect the error when the login credentials are incorrect, however, in this case, they are correct.
My question: Can you connect to FileZilla via PHP? I am sure the answer must be 'Yes' however due to the technical difficulties currently I would not be surprised otherwise.
Potentially there is an error in the formatting of the connection function.
var $host = "xx.xx.xx.xx";
var $user = "xx";
var $pass = "xx";
var $connect;
function serverConnection()
{
$conection = mysqli_connect($this->host, $this->user, $this->pass) or die
("Connection failed: " . mysqli_connect_error());
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$this->connect = $conection;
}
return $this->connect;
}
The goal is to be able to upload files from a form to FileZilla, to act as users profile pictures.
Currently, you're using mysqli_connect which connects to a database server, you need to connect to an FTP server, so you should use the FTP functions. You should first connect and then login.
It should look something like this:
$server = 'myServer';
$user = 'myUsername';
$pass = 'myPassword';
$connect = ftp_connect($server) or die('Could not connect to FTP-server.');
if(ftp_login($connect, $user, $pass)) {
echo 'Connected to FTP-server.';
}
i wrote a php script which should connect me with my database. I also uploaded the files in the public_html section, but it always throws this error :
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /Applications/XAMPP/xamppfiles/htdocs/FoodHelperSwift/db/public_html.php on line 24
Here is the line : $this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
This is my code :
public_html
var $conn = null;
var $result = null;
public $dbhost = null;
public $dbname = null;
public $dbuser = null;
public $dbpass = null;
function __construct($dbhost, $dbuser, $dbpassword, $dbname) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpassword;
$this->dbname = $dbname;
}
public function openConnection()
{
$this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
echo "YESSSS";
echo $this->dbhost;
echo $this->dbuser;
echo $this->dbpass;
echo $this->dbname;
if(mysqli_connect_errno())
{
throw new Exception("Could not connect with database");
$this->conn->set_charset("utf8");
}
}
public function closeConnection()
{
if ($this->conn != null)
{
$this->conn->close();
}
}
}
and
register user
:
require("../db/public_html.php");
$dbhost = "127.0.0.1";
$dbname = "xxxxxxxx";
$dbuser = "xxxxxxxxx";
$dbpassword = "xxxxxxx";
$returnValue = array();
if(empty($_REQUEST["userEmail"]) || empty($_REQUEST["userPassword"])
|| empty($_REQUEST["userFirstName"])
|| empty($_REQUEST["userLastName"]))
{
$returnValue["status"]="400";
$returnValue["message"]="Missing required information";
echo json_encode($returnValue);
return;
}
$userEmail = htmlentities($_REQUEST["userEmail"]);
$userPassword = htmlentities($_REQUEST["userPassword"]);
$userFirstName = htmlentities($_REQUEST["userFirstName"]);
$userLastName = htmlentities($_REQUEST["userLastName"]);
$salt = openssl_random_pseudo_bytes(16);
$secured_password = sha1($userPassword . $salt);
$dao = new MySQLDAO($dbhost, $dbuser, $dbpassword, $dbname);
$dao->openConnection();
The password etc. is right and i also tried localhost, but then i got an error that he cant find the file maybe you could help me.
Most likely you're not following steps provided by your website hosting provider.
Third party hosting solutions usually require you setup your remote IP
From the error message you specified it looks like you're trying to do this from your own home XAMP web service.
First - the basics
:
localhost - won't work from home - because that's going to look for your own MySQL database not the hosted db
Second - logging in from home (or remotely)
read the docs (always a good idea) Remote access to Bluehost MySQL
Use the following configuration settings for connecting to your database
Host name = (use the server IP address)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (the password you entered for that database user)
MySQL Connection Port = 3306
TCP or UDP, either is fine.
Allowing a Remote Server to Access Your Database
Before connecting to MySQL from another computer, the connecting computer must be enabled as an Access Host.
Log into cPanel and click the Remote MySQL icon, under Databases.
Type in the connecting IP address, and click the Add Host button.
Note: You can find and add your IP address directly from this tool. Look for Your IP is: 123.123.12.123 [Add]. Clicking the [Add] link will input your IP into the field box below.
Click Add, and you should now be able to connect remotely to your database.
To troubleshoot this, strip your code down to the basics. Make yourself a little testMyDb.php file, containing only the minimal stuff. For example:
$dbhost = "127.0.0.1";
$dbname = "xxxxxxxx";
$dbuser = "xxxxxxxxx";
$dbpassword = "xxxxxxx";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
Once you have that working, you can proceed to debug your php class and make sure you are setting things up correctly.
Your file named public_html.php contains some code that's part of a php class implementation (for example __construct()), but I don't see a class ClassName { line to set up a class definition. It's possible you've copied some fragments of code from somewhere without getting it all.
If your simple test DOESN'T work, check with bluehost's tech support krewe. You may need some special credentials or database name to connect to MySQL from one of their Windows hosts.
If you're using the MySQL server on a bluehost machine, and trying to connect to it from your local machine, that will not work (especially not with 127.0.0.1). You'll need to configure bluehost to allow remote MySQL connections, and you'll have to use the actual MySQL hostname.
Hi I am making a login/register database. I am not hosting the database on the same server so how do I make it point to my separate domain? Also if you can tell me what the root is pointing to... Thx
Here are my files:
db.php
<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('register');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>
Links (my scripts and original scripts): https://docs.google.com/document/d/1u60X_mKd9z548qrh_VjdyTx3hziiZiYPLUa_rJX11mQ/edit?usp=sharing
For starters, DON'T USE mysql_connect()! Use either mysqli or PDO. Second, don't have your application log in to MySQL as root; create an application-specific unprivileged user (with a password!) for this purpose.
You'll need to create your unprivileged user with connect privilege from the web server's IP or DNS address, and instead of connecting to localhost your PHP will need to connect to the DB server's IP or DNS address, like so:
$dsn = "mysql:host=mysqlserver.mynetwork.com;dbname=register";
try
{
$conn = new PDO($dsn, $appuser, $apppasswd);
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
You could try the following example
$server = "192.168.1.1"; //server name or IP Address
$username = "root"; //database username
$password = "password"; //database password
$database = "mydatabase"; //database to connect to
$connection = mysqli_connect( $server, $username, $password, $database);
if (!$connection){
die("Database Connection Failed" . mysqli_error());
}
else{
//sql statement
}
mysqli_close($connection);
Thanks
if (!empty($_POST)) {
$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$db = $_POST['db'];
echo '<pre>';
print_r($_POST);
$con = #mysqli_connect($host . ":3360", $user, $pass, $db);
// $con=#mysqli_connect('192.168.100.42','root','vertrigo','skates');
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo 'connected';
}
#mysqli_close($con);
}
I'm using this script to access remote db server in local(basically i want to access local db server through live webiste), howewer, I'm getting an error:
Failed to connect to MySQL: Unknown MySQL server host
'192.168.100.42:3360' (11004)
Please help to get out from this.
192.168.100.42 looks like a local IP. You'd need to try to connect to your static public IP and then forward port 3306 in your router to the 192.168.100.42 machine.
That's not your only problem;
Just because $_POST is not empty, don't assume it has those array keys set and not empty. Syntax like
if(isset($_POST['user'] && !empty($_POST['user'])))
Is much better.
Also, never use $_POST on any database interaction without sanitisation, and never connect to a database with the root user.
I don't know your exact application, but it's impossibly insecure.