Usando PHP para adicionar Facebook Open Graph Ação Read

I’m trying to get Facebook to publish a read action using PHP. I’ve coded it totally wrong and need a little help:

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

<?php

curl -F 'access_token=MY ACCESS TOKEN'
     -F 'article=echo 'echo curPageURL();'
        'https://graph.facebook.com/me/news.reads'

?>

The second part is that bit I can’t translate into PHP properly. I’ve no idea where to start as I’m a novice with PHP and only just learning the Open Graph API.

Tagged , , , | Deixe um comentário

Erro em consulta, o que é Resource id #9?

I have following code..

$query = "SELECT quote, author FROM quotes ORDER BY id DESC";
$resut = mysql_query($query, $connection) or die(mysql_error());

echo $result; //for debuggin purpose

while($result_set =  mysql_fetch_array($result)) {
    echo '<div class="pullquote">';
    echo $result_set['quote'];
    echo ' - ';
    echo $result_set['author'];
    echo '</div>';
}

and this doesn’t works! The table is not empty FYI, all I see in the output is:

Resource id #9

I am not being able to figure out what this Resource id #9 meios.
As I tested SELECT quote, author FROM quotes ORDER BY id DESC in phpmyadmin, that just works fine and produces desired result, but not in here. I wonder what is wrong with the code or something?

If I do following,

$array = mysql_fetch_assoc($result);
var_dump ($array);

Ele retorna, bool(false). What does that mean here?

Tagged | Deixe um comentário

Inserir valor na tabela do usuário divisão mensagens onde user = division.divisionid

Can anyone shed any light on how I insert a table entry in my messages table for each user.ID where the users.MM_Division = division.divisionid

I want to include the user ID value in the messages.messagesuserid

I think I need a while loop but I’m not sure how I implement it when dealing with a insert query.

Atualmente, em 1 message row is inserted into the messages table on the messageuserid value posts as NULL

Obrigado

Aqui está o meu código:

session_start();

$colname_division = "-1";
if ((isset($_GET['divisionid'])) && ($_GET['divisionid'] != "")) {
      $colname_division = $_GET['divisionid'];

mysql_select_db($database_connect, $connect);
$query_users = sprintf("SELECT users.*, division.* FROM users INNER JOIN division ON division.divisionid = users.MM_Division WHERE divisionid = %s", GetSQLValueString($colname_users, "int"));
$users = mysql_query($query_users, $connect) or die(mysql_error());
$row_users = mysql_fetch_assoc($users);
$totalRows_users = mysql_num_rows($users);

// MESSAGE USERS DIVISION ARCHIVED
    $messageinsertSQL = sprintf("INSERT INTO messages (message, messageuserid) VALUES ('The division " . $row_division['division'] . " has been archived by " . $_SESSION['MM_Username'] . " please select a new division', '" . $row_users['ID'] . "')",GetSQLValueString($_GET['divisionid'], "int"));
    mysql_select_db($database_connect, $connect);
    $Result4 = mysql_query($messageinsertSQL, $connect) or die(mysql_error());

// REDIRECT
    $updateGoTo = "../divisions.php";
        if (isset($_SERVER['QUERY_STRING'])) {
            $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
            $updateGoTo .= $_SERVER['QUERY_STRING'];
        }
    header(sprintf("Location: %s", $updateGoTo));

    mysql_free_result($division);
    exit;
}
Tagged , , , | Deixe um comentário

Conexão SSH para a Amazônia Instância EC2 Via PHP

Trying to connect to an Amazon EC2 instance using a .pem file, PHP, and phpseclib.

I have tried what’s mentioned in this post:
ssh access to ec2 from php

Contudo, Eu continuo recebendo “Erro 111. Connection refused in…”

When I connect from my own machine using ssh and the same .pem file, there are no errors.

Here is the code from the original post that I am using:

include('Net/SSH2.php');
include('Crypt/RSA.php');

$key = new Crypt_RSA();

$key->loadKey(file_get_contents('/pathtokey.pem'));

$ssh = new Net_SSH2('ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com');
if (!$ssh->login('user', $key)) {
exit('Login Failed');
}
Tagged , , | Deixe um comentário

PHP MySQL condição de corrida session_set_save_handler

Eu escrevi um simples session_set_save_handler using a MySQL innoDB table as the storage backend. MySQL is 5.5.

Code looks like so (very simplified, but hopefully illustrates the flow of code), Eu estou usando RedBean ORM for interacting with the database, but the commands should be clear in showing what was being written, read or deleted.:

class MySession{

    private $_database;  

    public function  __construct($database){
       //database object is injected using dependency injection then assigned to private var

       //Hook up handlers
       session_set_save_handler(
        array($this, "open"),
        array($this, "close"),
        array($this, "read"),
        array($this, "write"),
        array($this, "destroy"),
        array($this, "garbageCollection"));
       }

       //Register the shutdown function
       register_shutdown_function('session_write_close'); 

       //start
       session_start();

       //Regenerate session id
       //(NOTE: in production code, the id is regenerated every 10 minutes,
       //but regenerating allows us to trigger the race condition for demonstration.
       session_regenerate_id(TRUE);

    public function open($savePath, $sessionName){
        $this->_database->exec('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
        $this->_database->begin(); //Begin Transaction
        return true;
    }   

    public function close(){
        $this->_database->commit(); //Commit the transaction
        return true;
    }

    public function read($id){

        $this->_database->exec('SELECT * FROM session WHERE identifier = ? LOCK IN SHARE MODE', array($id));
        $session = $this->_database->findOne('session', 'identifier = ?', array($id));
        return $session->data;
    }

    public function write($id, $sessionData){

        $this->_database->exec('SELECT * FROM session WHERE identifier = ? FOR UPDATE', array($id));
        $session = $this->_database->findOne('session', 'identifier = ?', array($id));

        //We need to create a new session
        if ($session == NULL){
            $session = $this->_database->dispense('session');
        }

        $this->_database->store($session);
        return TRUE;
    }

    public function destroy($id){
        $this->_database->exec('SELECT * FROM session WHERE identifier = ? FOR UPDATE', array($id));
        $session = $this->_database->findOne('session', 'identifier = ?', array($id));

        if ($session != NULL){
            $this->_database->trash($session);
        }
        return TRUE;
    }

    public function garbageCollection($maxlifetime){
        $old = ... //Calculate the time for expired sessions

        $this->_database->exec("DELETE from session WHERE last_activity < ?", array($old));
        return TRUE;
    }
}

The problem is that even with the locking in place, if I send multiple requests to the application (por exemplo, usando AJAX), the race condition still occurs and the data stored in the session is lost. I have pinned it down to session_regenerate_id(TRUE), which deletes the previous session to being the cause of the issue. Contudo, even with the row locking, the issue still occurs.

I have looked at this página, as well as some código from that author, but that uses MyISAM tables which implements table locking.

Can anyone shed some light as to why the locking is not making a difference and perhaps offer some solutions to this problem?

Tagged , , , , | Deixe um comentário

Add Custom HML Code to WordPress Child Theme Without Template File Change?

I am working with a WordPress child theme, and I’d like to insert a custom line of HTML code. Normalmente, I’d simply put this extra HTML code in header.php, and while I know that I can copy the parent header.php and edit it in the child theme as the child header.php, I don’t want to do this because I will have to go back and re-update the header.php file when I eventually update the parent theme.

Is the best approach to simply use a functions.php file in the child theme and call the wp_head hook to insert the text? I don’t like the idea of the text being in the <head></head> area because it really should be in the <body></body>, but I will ultimately position the code with .css anyway.

Tagged | Deixe um comentário

For a review website, which language?

I am thinking of building a review website and i was thinking about using php. What language would be good for a website like ratemyprofessor? would ruby be better?

Tagged , , | Deixe um comentário

php get mysql result not as array, but as text

I want to get text result like:

+----+-------+----------------------------------+----+
| id | login | pwd                              | su |
+----+-------+----------------------------------+----+
|  1 | root  | c4ca4238a0b923820dcc509a6f75849b |  1 |
+----+-------+----------------------------------+----+
1 row in set (0.00 sec)

em PHP (corda).

Example in php:

$query = mysql_query("SELECT * FROM users");
for (; $row = mysql_fetch_assoc($query); $data[] = $row);

I get array of arrays ($dados):

$data =
   0 => (id=>1, login=>root..)

But i want to get this as corda:

+----+-------+----------------------------------+----+
| id | login | pwd                              | su |
+----+-------+----------------------------------+----+
|  1 | root  | c4ca4238a0b923820dcc509a6f75849b |  1 |
+----+-------+----------------------------------+----+
1 row in set (0.00 sec)

By the way for queryinsert into users set login =sp’, pwd = 1, su = 0″, this string must beQuery OK, 1 row affected, 2 avisos (0.18 sec)”.

Like sql terminal though php!

Tagged , , | Deixe um comentário

Sending a POST request without submitting an HTML form

Eu estou querendo saber, is it possible to send an HTTP POST in PHP without using an HTML form. Can this be done internally using PHP? Se não, maybe using JavaScript or jQuery?

Tagged , | Deixe um comentário

How to keep the Chinese or other foreign language as they are instead of converting them into codes?

DOMDocument seems to convert Chinese characters into codes, por exemplo,

你的乱发 will become ä½ çš„ä¹±å‘

How can I keep the Chinese or other foreign language as they are instead of converting them into codes?

Below is my simple test,

$dom = new DOMDocument();
$dom->loadHTML($html);

If I add this below before loadHTML(),

$html = mb_convert_encoding($html, "HTML-ENTITIES", "UTF-8");

Recebo,

你的乱发

Even though the coverted codes will be displayed as Chinese characters, 你的乱发 still are not 你的乱发 what I am after….

Tagged , , , , | Deixe um comentário
2207 páginas