0

我想在用户登录表单后检查用户凭据,然后如果用户名和密码正确,用户将重定向到 upload.php 页面,上传图像和状态后,图像和状态将发布在用户 twit 上

这是我的 verifikasi.php 代码

<h2>Verifikasi ID Twitter...</h2>
/*verification of user credentials
after validation of username and password success, redirect to upload image and status page
but if validation of username and password fail, back to login page
*/

<?php

require_once('codebird.php');
$cb = new \Codebird\Codebird;

$id = $_POST['id'];
$pass = $_POST['pass'];

 //if($_POST['loginTwitter'] == "Submit"){
 //if(isset($_POST['loginTwitter'])){
 if(isset($id) && isset($pass)){
    //cek bener apa engga nya

    //if($_POST['id'] == '' || $_POST['pass'] == ''){ header('login.php'); }

    $cb::setConsumerKey('somekey', 'somekeysecret');
    $cb::getInstance();
    $cb->setToken('tokenaccess', 'tokenaccesssecret');

    $code = $cb->account_verifyCredentials();
    if($code == 200){ 
        //$reply = $cb->oauth2_token();
        //$bearer_token = $reply->access_token;
        header('upload.php');
    }
    else{ header('login.php'); }

  //echo "Redirect to Upload Image...."; for($i = 0; $i <= 20000000; $i++); header('upload.php');
 }

 else{
    echo "<br />";
    echo "<h3>Something went wrong... Please Check Again Your Credentials</h3>";
  }

?>

这是 post.php 页面(用于使用 update_with_media API 向用户 twit 发布图像和状态

<div id="photo_tweet">
<h2>Photo Tweet</h2>
<br />

<?php require_once('codebird.php'); ?>

<?php
  function redirectToUpload(){
    echo "Redirect...";
    for($i = 0; $i <= 20000000; $i++);
    header('upload.php');
  }
?>

<?php
$imgExt = array("jpeg", "jpg", "png");
$currImgExt = end( explode(".", $_FILES["file"]["name"]) );

if($_POST['uploadTwit'] == "Submit"){

 if ((($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/x-png")
    || ($_FILES["file"]["type"] == "image/png") || $_POST['status'] == '')
    && ($_FILES["file"]["size"] < 20000)
    && in_array($currImgExt, $imgExt))
 {
    if ($_FILES["file"]["error"] > 0){
        echo "Error: " . $_FILES["file"]["error"] . "<br>";
        redirectToUpload();
    }
    else{
          $params = array(
            'status' => $_POST['status'],
            'media[]' => $_FILES["file"]["name"]
          );

          /*
          $data_user = array(
            'user_id' => ,
            'screen_name' => 
          );
          */
       $reply = $cb->statuses_updateWithMedia($params);
    }
  }
 }
 else { echo "Invalid Image File or Invalid File Size or Twit cannot empty! Please check agian your image file before proceed!"; redirectToUpload(); }
?>

<p>You Just Succeed Post image and status!</p>

</div>

verifikasi.php 的问题是注意:第 36 行的 C:\wamp\www\twcodebird\verifikasi.php 中的类 stdClass 的对象无法转换为 int

我想在verifikasi.php 中返回状态码,如果code = 200 则用户重定向到upload.php 页面,但是从错误返回来看,似乎我的代码返回错误......我该怎么办?

对于 post.php 我还没有运行它,因为我想确保首先验证用户凭据

4

0 回答 0