I get this message when I try to access my site.
The site was working properly, and I tried to add google analytics...
Anyway, sodabrasil was a site created out of WP.
sodabrasil.com/paskin was WP.
We did the integration of logins. Everything was working.
When I run http://sodabrasil.com/dbtest.php, it says it's connected.
this is the debug code.
<?php
//connect to MySQL Server
$conn = mysql_connect("localhost", "*****", "******");
if (!$conn)
{
die(mysql_error());
}
else
{
echo "1. Successfully connected to MySQL database server.<br /><br />";
}
// select database
$db_sel = mysql_select_db('*********', $conn);
if (!$db_sel)
{
die ('cant\'t use database: ' . mysql_error());
}
else
{
echo "2. WordPress database selected. <br />";
}
?>
the database * is the DB sodabrasil uses for the login.
But accessing sodabrasil is blocked even before the login!!!
I am not a professional coder, which makes things a lot harder.
This is the real config file:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
define('WP_USE_THEMES', false);
//echo $_SERVER['DOCUMENT_ROOT'];
//die;
//require_once('./blog/wp-blog-header.php');
require_once('/home/houswe5/public_html/sodabrasil.com/paskin/wp-blog-header.php');
global $mysqli;
$server = 'localhost'; // The host you want to connect to.
$username = '****'; // The database username.
$password = '*****'; // The database password.
$database = '*******'; // The database name.
$dbms = 'MySQL 5';
$dbport = '3306';
//$dbh = mysql_connect($server, $username, $password) or die("Unable to connect to SQL server");
//$my_db = #mysql_select_db($database) or die("Unable to select database");
$mysqli = new mysqli($server, $username, $password, $database);
//$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error " . mysqli_error($link));
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;die;
}
// If you are connecting via TCP/IP rather than a UNIX socket remember to add the port number as a parameter.
?>
Exact same credentials.
But this url (http://sodabrasil.com/db_connect.php) throws the error message in regards to DB.
Thank you for you help.
G.
Related
Most answers were that it would be a right issue. But I assume not in this case, because mysql-connection still worked.
I am trying to connect to a mariadb10, which was on a server in my network
I am trying to connect from my localhost.
If I try in my terminal:
myuser#mylocalComputer ~ $ mysql -h myserver -P 3307 -u mydbuser -pmyconfidentalpassword
everything works fine!!
But If I try to connect by php scrypt by pdo I get the error:
<?php
$dsn = 'mysql: host=myserver:3307;dbname=mydbname';
$username = 'mydbuser';
$password = 'myconfidentalpassword';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, $username, $password, $options);
if(! $dbh ) {
die('Could not connect: ' . mysql_error());
}
$sql = 'select * from foo;';
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not select data: ' . mysql_error());
}
echo "Synced data successfully\n";
mysql_close($conn);
?>
The Error was:
PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access
denied for user 'mydbuser'#'localhost' (using password: YES) in
/home/myuser/Projekte/Hibiscus_extend/Hib_Nightly_sync.php:8
Stack trace:
/home/myuser/Projekte/Hibiscus_extend/Hib_Nightly_sync.php(8):
PDO->__construct('mysql: host=myse...', 'mydbuser',
'myconfidentalpassword', Array) {main} thrown in
/home/myuser/Projekte/Hibiscus_extend/Hib_Nightly_sync.php on line 8
What did I do wrong, and where?
Oh Oh Oh!
I found the solution!
The reason for the connection problem were just the empty spaces in $dsn
Wrong:
$dsn = 'mysql: host=myserver:3307;dbname=mydbname';
works fine
$dsn = 'mysql:host=myserver:3307;dbname=mydbname';
i am try to get google account authentication for my app, but when i choose the account to log in i get the error redirect_uri_mismatch,
at google console i create Client ID for web application
first i try to run the app on local host with the following settings
REDIRECT URIS : http://localhost/myapppath/
but get the same error
also i try to host my app at heroku with the following Client ID for web application settings
but get the same error, i search many times on stackoverflow with no success to find a solution
this is my code, it is a test code to get the uploaded videos of a user
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
session_start();
/*
* You can acquire an OAuth 2.0 client ID and client secret from the
* Google Developers Console <https://console.developers.google.com/>
* For more information about using OAuth 2.0 to access Google APIs, please see:
* <https://developers.google.com/youtube/v3/guides/authentication>
* Please ensure that you have enabled the YouTube Data API for your project.
*/
$OAUTH2_CLIENT_ID = '42965713xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxercontent.com';
$OAUTH2_CLIENT_SECRET = 'y9AWlbxxxxxxxDqdQwJ';
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
FILTER_SANITIZE_URL);
$client->setRedirectUri($redirect);
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
if (isset($_GET['code'])) {
if (strval($_SESSION['state']) !== strval($_GET['state'])) {
die('The session state did not match.');
}
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: ' . $redirect);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
// Check to ensure that the access token was successfully acquired.
if ($client->getAccessToken()) {
try {
// Call the channels.list method to retrieve information about the
// currently authenticated user's channel.
$channelsResponse = $youtube->channels->listChannels('contentDetails', array(
'mine' => 'true',
));
$htmlBody = '';
foreach ($channelsResponse['items'] as $channel) {
// Extract the unique playlist ID that identifies the list of videos
// uploaded to the channel, and then call the playlistItems.list method
// to retrieve that list.
$uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];
$playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
'playlistId' => $uploadsListId,
'maxResults' => 50
));
$htmlBody .= "<h3>Videos in list $uploadsListId</h3><ul>";
foreach ($playlistItemsResponse['items'] as $playlistItem) {
$htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'],
$playlistItem['snippet']['resourceId']['videoId']);
}
$htmlBody .= '</ul>';
}
} catch (Google_ServiceException $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
$_SESSION['token'] = $client->getAccessToken();
} else {
$state = mt_rand();
$client->setState($state);
$_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
$htmlBody = <<<END
<h3>Authorization Required</h3>
<p>You need to authorize access before proceeding.<p>
END;
}
?>
<!doctype html>
<html>
<head>
<title>My Uploads</title>
</head>
<body>
<?=$htmlBody?>
</body>
</html>
What credentials type you choose depends on the application you want to build. 'Client ID for web application' should work fine for you.
The URIs you specify in Redirect URIs have to point to the actual script file, like http://example.com/index.php. I don't think http://example.com is supposed to work.
i found the solution after replacing this line
$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
by this
$redirect = 'http://localhost/myappname';
i do not know why it is not working when it take the full path of the redirect class
I've been trying to experiment with MongoDb, and when I run the script to connect, it can't because the password uses the # symbol.
To connect to MongoDb
mongodb://username:password#localhost
But as my password to connect to MongoDb uses the # symbol, it can't connect due to the # symbol.
For example;
new MongoClient("mongodb://mongo:p#assword#localhost);
Will throw the following error;
PHP Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: assword!#localhost:27017: Couldn't get host info for assword!#localhost'
As you can see, it thinks the first # in the password is the seperator for password and host.
Is there a way to connect, and allow the # symbol in the password when using MongoClient?
http://uk3.php.net/manual/en/mongoclient.construct.php you can pass the username and password as an options array
new MongoClient("mongodb://localhost:27017", array("username" => "joe", "password" => "test"));
You can try by this code. Just pass your input as per dynamic value.
try {
$m = new MongoClient("mongodb://HOST:" . MNG_PORT, array(
"username" => MNG_USER,
"password" => MNG_PWD
)); // connect local Mongo
$db = $m->selectDB("DBNAME"); // select DB
$collection = $db->collections; // connect to collection
} catch ( MongoConnectionException $e ) {
echo 'Couldn\'t connect to mongodb, is the "mongo" process running?';
exit();
}
It works just fine on my iPhone 3GS, but several employees with iPhone 4 and up are not able to log into my site through safari because their login credentials are not being saved to $_SESSION. If they download chrome onto their phones it works.
Any idea how to get this working?
When a user attempts to log in, their credentials are first verified as being accurate, and when they are they are sent to:
validate_login.php
<?php
session_start();
// sent from the login form
// employee id and username
$employeeId = $_POST['employee_id'];
$password = $_POST['password'];
//make connection to database, bail if no connection
$connection = odbc_pconnect('workorders','','');
if (!$connection) { exit("Connection Failed: " . $connection); }
//retrieve usernames and passwords
$sql = "SELECT * FROM LoginTable WHERE EmployeeID='$employeeId' and Password='$password'";
$rs = odbc_exec($connection, $sql);
if (!$rs) { exit("Error in SQL"); }
if(odbc_fetch_row($rs)) {
// register employeeId and password in session cookie and redirect to homepage
$_SESSION['employee_id'] = $employeeId;
header("location:../../home.php");
}
else {
header("location:../../login.php?error=0");
}
//close connection
odbc_close($connection);
?>
This is about as simple as you can be... any idea why it wouldn't be working? When I do a check at the top of every page that they are logged in:
<?php
session_start();
//validate user logged in; if not, redirect to login
if(!isset($_SESSION['employee_id'])){
header("location:login.php");
}
?>
It just thinks they're not logged in and throws them back out to login.php
Again, this is just an issue on Safari for newer iPhones as far as I can tell. Suggestions?
I have apache down checker script (remote server), but I think it doesn't work if httpd has a timeout issue or something similar.
For example, site was offline, but the server was online status.
Should I put timeout stuff or something else? How??
<?php
function GetServerStatus($site, $port)
{
$status = array("OFFLINE", "ONLINE");
$fp = #fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
return $status[0];
} else
{ return $status[1];}
}
?>
<?php
$status = GetServerStatus('xxx.xxx.xxx.xxx',80);
if($status == 'OFFLINE') {
$message = "Server is down now!!";
}
?>
I don't see how this can possibly report incorrectly. You could consider sending a GET / request and timing it out.
You could also consider closing the socket in the success case.