English 中文(简体)
Http URL保护工作在当地进行,但在服务器上失败
原标题:Http URL protection works in localhost but fails on the server

Am using this代码用于认证我的URL。

  1. 其工作罚款载于我的<代码> 当地东道,但在我装上服务器(goDaddy)时,它一再要求用户名和密码。

  2. 我的大麻控制这些用户名和密码田,并将其与我的数据库连接。

为此,正在使用这样的法典:

$conid = mysql_connect("localhost", "root", "");
if(!$conid) {
  die("sorry unable to establish a connection".mysql_error());
}
echo "connected succesfully<br>";
mysql_select_db("passurl", $conid);
$rr = mysql_query("select password from validate where username= $user  ");
while($row = mysql_fetch_array($rr)) {
  $x = $row[ password ];
}
if($x == $password) {
  //take into the website
}

因此,用户名和密码在成功认证后进入该页。

Am using PHP-MYSQL, as I ve preliminary knowledge in it, am newbie to programming.

帮助我确定上述两个问题,并制定适当的测试守则。

Edit: Issue one is working locally and am using the same code as provided in the link. Issue two is am trying to retrieve those username and password fields from my local database so as login can be granted, on my localhost(if it works on later stage I ll take the database to online).

Edit-2:

<代码>ty.php 守则

<?php

$auth_realm =  Access restricted ;

require_once  auth.php ;

echo "You ve logged in as {$_SESSION[ username ]}<br>";
echo  <p><a href="?action=logOut">LogOut</a></p> 

?>

<center><h1>now you see the protected content</h1></center>

www.un.org/spanish/ga/president 页: 1

<?php   
  $_user_ =  test ;
  $_password_ =  test ;
  session_start();

$url_action = (empty($_REQUEST[ action ])) ?  logIn  : $_REQUEST[ action ];
$auth_realm = (isset($auth_realm)) ? $auth_realm :   ;

if (isset($url_action)) {
    if (is_callable($url_action)) {
        call_user_func($url_action);
    } else {
        echo  Function does not exist, request terminated ;
    };
};

function logIn() {
    global $auth_realm;

    if (!isset($_SESSION[ username ])) {
        if (!isset($_SESSION[ login ])) {
            $_SESSION[ login ] = TRUE;
            header( WWW-Authenticate: Basic realm=" .$auth_realm. " );
            header( HTTP/1.0 401 Unauthorized );
            echo  You must enter a valid login and password ;
            echo  <p><a href="?action=logOut">Try again</a></p> ;
            exit;
        } else {
            $user = isset($_SERVER[ PHP_AUTH_USER ]) ? $_SERVER[ PHP_AUTH_USER ] :   ; 
            $password = isset($_SERVER[ PHP_AUTH_PW ]) ? $_SERVER[ PHP_AUTH_PW ] :   ; 
            $result = authenticate($user, $password);
            if ($result == 0) {
                $_SESSION[ username ] = $user;
            } else {
                session_unset($_SESSION[ login ]);
                errMes($result);
                echo  <p><a href="">Try again</a></p> ;
                exit;
            };
        };
    };
}

function authenticate($user, $password) {
    global $_user_;
    global $_password_;

    if (($user == $_user_)&&($password == $_password_)) { return 0; }
    else { return 1; };
}

function errMes($errno) {
    switch ($errno) {
        case 0:
            break;
        case 1:
            echo  The username or password you entered is incorrect ;
            break;
        default:
            echo  Unknown error ;
    };
}

function logOut() {

    session_destroy();
    if (isset($_SESSION[ username ])) {
        session_unset($_SESSION[ username ]);
        echo "You ve successfully logged out<br>";
        echo  <p><a href="?action=logIn">LogIn</a></p> ;
    } else {
        header("Location: ?action=logIn", TRUE, 301);
    };
    if (isset($_SESSION[ login ])) { session_unset($_SESSION[ login ]); };
    exit;
}

?>

一旦我们打上了<代码>ty.php,它就要求用户名称和密码,并成功验证该密码显示受保护。 所有这一切都在当地进行罚款,但是没有在服务器上工作。

Can someone pls help me out of this
Thanks in advance :)

问题回答

您需要建立一个数据库用户名称和口号,供您的goDaddy主机服务,root,空密码可以带你。 其根基是您的当地服务器的缺省用户名称,你打上了任何密码,因此,<代码>“<>>>”为您设计的密码。 你们必须建立一个用户名称,在你的远程服务器上设置一个密码,以便工作。

mysql_connect("your-host-server", "a-username", "a-secret-password"); // Password can t be empty and username can t be root, hope you understand

您在座标上,但只是在座标之后检查一个价值。

你的法典是:

while($row = mysql_fetch_array($rr)) {
  $x = $row[ password ];
}
if($x == $password) {
  //take into the website
}

应当:

while($row = mysql_fetch_array($rr)) {
    if ($password == $row[ password ]) {
        // take into the website
    }
}




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签