Jump to content

Selecting a mysql server at registration


4me
Go to solution Solved by Jacques1,

Recommended Posts

Jacques1
<?php
if(isset($_POST['submit']))
{ 
session_start();
if($_POST['kapcha'] != $_SESSION['rand_code']) 
exit ("<center>error code image</center>");
else 
echo "";
if (isset($_POST['login']))
{
$login = $_POST['login'];
if ($login == '')
{
unset($login);
}
} 

$err = array();

if(!preg_match("/^[a-z0-9\_]+$/", $login))
{
exit ("<center>Username can only contain letters of the Latin alphabet and numbers!</center>");
}

if( preg_match( "/[а-яёА-ЯЁ|\s]/", $login ) )
    {
exit ("<center>Username may contain only letters and numbers!</center>");
    }

if (isset($_POST['password']))
{
$password = $_POST['password'];
if ($password =='')
{
unset($password);
}
}

if (strlen($login) < 3 or strlen($login) > 25)
{
exit ("<center>Login must be at least from <b> 3 </ b> characters and no more than: <b>25<b>, go back and try again</center>");
}

if    (strlen($password) < 6 or strlen($password) > 20) {
            exit    ("<center>The password should consist of at least from <b> 6 </ b> characters and no more than from <b> 20 </ b>, go back and try again</center>");
            }    
if (empty($login) or empty($password))
{
exit ("<center>You do not have entered all the information, go back and fill in all fields!</center>");
}

$login = stripslashes($login);
$login = htmlspecialchars($login);
$password = stripslashes($password);
$password = htmlspecialchars($password);
$login = $_POST['login'];
$password = $_POST['password'];
//$password = htmlspecialchars($password);
//$password = md5($password);
//удаляем лишние пробелы
$login = trim($login);
$password = trim($password);

include ("mysql.php"); 
$result = mysql_query("SELECT username FROM users WHERE username='$login'", $db);
$myrow = mysql_fetch_array($result);
if (!empty($myrow['username']))
{
exit ("<center>Sorry, you entered login is already registered. Please enter a different username.</center>");
}
$result2 = mysql_query ("INSERT INTO users (username,password) VALUES('$login','$password')");
$login = mysql_real_escape_string($_POST['login']);
$password = mysql_real_escape_string($_POST['password']);

if ($result2=="TRUE")
{
echo "<center>You have successfully logged in! Now you can log in using your ID.</center>";
}
else {
echo "Error! You are not registred.";
}
}
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> 
<html>
<meta charset="utf-8"/>
<head>
    <link rel="stylesheet" href="css/styles.css">
	<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <title>Register</title>

</head>
<body>
<center><h3><a href="/">Jabber Server </a></h3></center>
<div>
<form action="../register.php?do=reg" method="post">
<label for="name">Login:</label> <input name="login" type="name" size="15" maxlength="15">
<br />
<label for="password">password:</label> <input name="password" type="password" size="15" maxlength="15">
<br />
<input name="md5" type="hidden">
<img src = "captcha.php" />
<br />
<input type = "text" name = "kapcha" />
<br />
<input type="submit" name="submit" value="Register">
<center>
</center>
</form>
</div>

</body>
</html>

I want to make as there https://jabber.ru/user/register

post-181505-0-07649200-1444950379_thumb.png

Link to comment
Share on other sites

It's still unclear to me what you mean by choosing the MySQL server. Do you have multiple database servers? Or are you talking about databases? In any case: Why do you have more than one?

 

By the way, the code has lots of problems. The mysql_* functions are obsolete since more than a decade and will be removed in PHP 7. Nowadays, we use PDO. Randomly throwing all this stripslashes(), htmlspecialchars() etc. at the user input also isn't a good idea.

Link to comment
Share on other sites

I have several databases

jabberserver1 - (localhost; user1;pass1;dbname1)

jabberserver2 - (localhost; user2;pass2;dbname2)

etc

I need to make sure that the user has registered by the server for registration jabberserver1 or jabberserver2 

the script would be entered into the database data for selected mysql server

Link to comment
Share on other sites

Why do you want two databases? Why not use one and separate the users within the database? Simply add a column which assigns the user to one of the two Jabber servers.

 

Maintaining two identically(?) structured databases is generally a very bad idea, because it makes the code more complicated, forces you to do everything twice (changes, backups) and can quickly lead to problems if you update one database but forget to update the other.

Link to comment
Share on other sites

  • Solution

I understand that you have multiple Jabber servers, but that doesn't mean you should have a separate database for each one of them. Or is this a specific requirement of the Jabber implementation you're using?

 

Anyway, if you absolutely need multiple databases, create an array which maps the different servernames to different MySQL connection parameters:

<?php

$jabberDatabases = [
    'jabber1.example.com' => [
        'host' => 'localhost',
        'user' => 'user1',
        'password' => 'pw1',
        'database' => 'db1',
    ],
    'jabber2.example.com' => [
        'host' => 'localhost',
        'user' => 'user2',
        'password' => 'pw2',
        'database' => 'db2',
    ],
];

Given the name of the jabber server, you can select the corresponding parameters for mysql_connect() and mysql_select_db().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.