2013-04-09 105 views
0

我在我的测试现场http://www.weddingsplanner.co.in/test/pdo.php没有找到

及彼这么多错误的index.php文件以及我在页面db.php中出现错误代码,但我认为这将解决,如果我会发现一些sloutions从这里

<?php 

    require_once 'config.php'; 

    function __autoload($class_name) 
    { 
     include_once 'library/' . strtolower($class_name) . '.php'; 
    } 

    $user = new User(); 

    $facebook = new Facebook(array(
     'appId' => FB_ID, 
     'secret' => FB_SECRET, 
    )); 

    if ($user->isLogged()) 
    { 
     $registerOrLoginNeeded = false; 
    } 
    else 
    { 
     $registerOrLoginNeeded = true; 

     /* 
      To disable auto login, comment the code used to login automatically. 
      (Must be used together with documented changes in JavaScript) 
      Start Here. 
     */ 
     $fbUser = $facebook->getUser(); 

     if ($fbUser) 
     { 
      try { 

       $userProfile = $facebook->api('/me'); 

       if ($user->fbLogin($fbUser)) 
       { 
        $registerOrLoginNeeded = false; 
       } 
       else 
       { 
        $db = Db::init(); 

        $sth = $db->prepare("SELECT * FROM users WHERE email = ?"); 
        $sth->execute(array($userProfile['email'])); 

        if (false != $sth->fetch()) 
        { 
         $sth = $db->prepare("UPDATE users SET facebook = ? WHERE email = ?"); 
         if ($sth->execute(array($fbUser, $userProfile['email']))) 
         { 
          if ($user->fbLogin($fbUser)) 
           $registerOrLoginNeeded = false; 
         } 
        } 
       } 

      } catch (FacebookApiException $e) { 
       $fbUser = null; 
      } 
     } 
     /* 
      End Commenting Here 
     */ 
    } 
?> 

<!DOCTYPE html> 

<html lang="en-US"> 
    <head> 
     <title>Simple Registration System</title> 
     <style> 
      body { font: normal 14px Verdana; } 
      h1 { font-size: 24px; } 
      h2 { font-size: 18px; } 
     </style> 
    </head> 
    <body> 

     <div id="wrap"> 

      <section id="main"> 

       <?php if (false === $registerOrLoginNeeded): ?> 

        <h1>Welcome</h1> 
        <p>You may now enjoy the site.</p> 
        <a href="logout.php">Logout</a> 

       <?php else: ?> 

        <div id="fb-root"></div> 
        <script type="text/javascript"> 
         window.fbAsyncInit = function() { 
         FB.init({ 
          appId  : '<?php echo $facebook->getAppID() ?>', // App ID 
          channelUrl : 'http://localhost.com/channel.html', // Channel File 
          status  : true, // check login status 
          cookie  : true, // enable cookies to allow the server to access the session 
          oauth  : true, // enable OAuth 2.0 
          xfbml  : true // parse XFBML 
         }); 
         FB.Event.subscribe('auth.login', function(response) { 
          /* 
           To have user login when FB login button is clicked 
           comment window.location.reload(); line and 
           uncomment the window.location = "fb_login.php"; 
           line. Must be used together with commenting the PHP part 
          */ 
          window.location.reload(); 
          //window.location = "fb_login.php"; 
         }); 
         FB.Event.subscribe('auth.logout', function(response) { 
          window.location.reload(); 
         }); 
         }; 
         (function(d){ 
         var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
         js = d.createElement('script'); js.id = id; js.async = true; 
         js.src = "//connect.facebook.net/en_US/all.js"; 
         d.getElementsByTagName('head')[0].appendChild(js); 
         }(document)); 
        </script> 

        <h1>Registration or login needed</h1> 

        <div style="float: left; margin-right: 15px;"> 

         <h2>Register</h2> 
         <p>You need to register to fully enjoy this site.</p> 

         <div class="fb-registration" 
          data-fields='[{"name":"name"}, 
             {"name":"birthday"}, 
             {"name":"location"}, 
             {"name":"gender"}, 
             {"name":"email"}, 
             {"name":"username","description":"Username","type":"text"}, 
             {"name":"password"}]' 
          data-redirect-uri="http://localhost.com/register.php" 
          width="300"> 
         </div> 

        </div> 

        <div style="float: left;"> 

         <h2>Login</h1> 
         <p> 
          If you already have an account you can login 
          using the form below: 
         </p> 
         <form action="login.php" method="POST"> 
          <div> 
           <label for="username">Username:</label> 
           <input type="text" id="username" name="username" /> 
          </div> 
          <div> 
           <label for="password">Password:</label> 
           <input type="password" id="password" name="password" /> 
          </div> 
          <div><input type="submit" value="Login" /></div> 
          <p> 
           If you previously registered for this site using Facebook, 
           you can now login using your Facebook account. 
          </p> 
          <div class="fb-login-button" data-show-faces="false" scope="email"></div> 
         </form> 

        </div> 
        <div style="clear:both;">&nbsp;</div> 

       <?php endif; ?> 

      </section> 

     </div> 

    </body> 
</html> 

这里是db.php中的代码

<?php 

class Db 
{ 
    private static $db; 

    public static function init() 
    { 
     if (!self::$db) 
     { 
      try { 
       $dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME; 
       self::$db = new PDO($dsn, DB_USER, DB_PASS); 
       self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
      } catch (PDOException $e) { 
       // Normally, we would log this 
       die('Connection error: ' . $e->getMessage() . '<br/>'); 
      } 
     } 
     return self::$db; 
    } 
} 
+2

嗯,'http:// www.weddingsplanner.co.in/test/library /'没有列出文件'pdo.php',所以这就是问题:) – silentw 2013-04-09 11:52:58

+0

检查你的路径,文件不存在有 – 2013-04-09 11:53:44

回答

0

请检查pdo.php文件库中的文件夹中存在。 __autoload函数尝试加载未定义的类。名为pdo的类必须已经调用。请确认。

+0

实际上我希望我的网站使facebook登录系统与脸部整合,我从这个[链接]下载代码(http://www.domagojsalopek.com/Details/Create-a-Registration-and-Login-System-using- Facebook-Registration-Plugin/21)...它不包含任何pdo.php – user2182602 2013-04-09 12:05:00

+0

我可以看到你的PHP配置设置吗?只需创建一个测试页面&只需echo phpinfo(); – 2013-04-09 13:01:16

+0

是的jenson它完成了! :-) – user2182602 2013-04-09 13:10:17

0

http://www.weddingsplanner.co.in/test/library/所示,它没有列出文件pdo.php

它试图将包含在这行代码的:

function __autoload($class_name) 
{ 
    include_once 'library/' . strtolower($class_name) . '.php'; 
} 

验证您的文件夹,并上传了必要的文件和错误应该是固定的!

+0

其实我想让我的网站登录系统与Facebook的整合,我从这个[链接]下载代码(http://www.domagojsalopek.com/Details/Create-a-Registration-and-Login-系统使用Facebook的注册插件/ 21)网站...它不包含任何pdo.php – user2182602 2013-04-09 12:01:49

+0

@ user2182602你可以发布文件'db.php'的代码? – silentw 2013-04-09 12:05:22

+0

我并没有真正进入Facebook SDK,只是偶尔在JS API上搞了几次......你能解释它如何使用'__autoload'方法来加载文件,比如'pdo'吗? – silentw 2013-04-09 13:13:12