elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Problemas de horarios en el servidor.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problemas de horarios en el servidor.  (Leído 1,891 veces)
#Aitor

Desconectado Desconectado

Mensajes: 173



Ver Perfil
Problemas de horarios en el servidor.
« en: 9 Julio 2013, 10:21 am »

Buenas.

Estoy intentando mandar un tweet mediante PHP... el caso es que en el localhost (horario GTM +1 madrid) funciona perfectamente, no obstante, a la hora de subirlo a un servidor que tiene como hora estados unidos es decir (GTM -5 ,  6horas de diferencia con respecto al español) el tweet no es enviado, dado que las horas no coinciden....

Este es el código que uso.

Código
  1. <?php
  2.  
  3.  
  4. require('twitteroauth.php'); // libreria
  5. define('_CONSUMER_KEY','datos....'); // consumer key
  6. define('_CONSUMER_SECRET','más datos...'); // consumer secret
  7. define('_OAUTH_TOKEN','datos....'); // access token
  8. define('_OAUTH_TOKEN_SECRET','datos....'); // access token secret
  9.  
  10.  
  11. function getConnectionWithAccessToken() {
  12.  $connection = new TwitterOAuth(_CONSUMER_KEY, _CONSUMER_SECRET,_OAUTH_TOKEN, _OAUTH_TOKEN_SECRET);
  13.  return $connection;
  14. }
  15.  
  16.  
  17. // Ejecutamos la conexión
  18. $connection = getConnectionWithAccessToken();
  19.  
  20. //Publicamos el mensaje en twitter
  21. $mensaje = "Aquí iría el mensaje bla bla bla.";
  22. $twitter= $connection->post('statuses/update', array('status' => $mensaje) );
  23.  
  24.  
  25.  
  26. ?>
  27.  

Perdonad la precaución, dónde pone datos obviamente van los datos asociados a la cuenta...

¿Cómo puedo indicarle al servidor que la hora tiene que ser GTM+1 y no GTM-5?

Gracias de antemano.


En línea

Mi algoritmo en PHP (estupideces y más).
Código
  1. while($Se_feliz){
  2.  Piensa_un_OBJETIVO(); // Sin excusas!
  3.  if($Tienes_un_objetivo){
  4.    Suspira(); // Sé paciente.
  5.    if($Consigues_el_objetivo){ echo "¡Felicidades #Aitor!";return;
  6.      //RETURN; ¿O volvemos a empezar?
  7.    }else{
  8.      Inténtalo_de_nuevo();
  9.    }
  10.  }
  11. }
peib0l
Wiki

Desconectado Desconectado

Mensajes: 3.493


freedom


Ver Perfil WWW
Re: Problemas de horarios en el servidor.
« Respuesta #1 en: 9 Julio 2013, 15:35 pm »

podrias poner el "twitteroauth.php" para ver como lo trata?


En línea

el-brujo
ehn
***
Desconectado Desconectado

Mensajes: 21.590


La libertad no se suplica, se conquista


Ver Perfil WWW
Re: Problemas de horarios en el servidor.
« Respuesta #2 en: 9 Julio 2013, 19:19 pm »

En el fichero php.ini de tu servidor (localhost) puedes cambiar la zona horaria del PHP:

Código:
[Date]
; Defines the default timezone used by the date functions
date.timezone = Europe/Madrid
En línea

#Aitor

Desconectado Desconectado

Mensajes: 173



Ver Perfil
Re: Problemas de horarios en el servidor.
« Respuesta #3 en: 9 Julio 2013, 21:16 pm »

En el fichero php.ini de tu servidor (localhost) puedes cambiar la zona horaria del PHP:

Código:
[Date]
; Defines the default timezone used by the date functions
date.timezone = Europe/Madrid

Buenas, lo que me interesa, es cambiar la hora del servidor web, no la del local, pues en el local funciona bien... ¡Gracias por la ayuda! :P

podrias poner el "twitteroauth.php" para ver como lo trata?

Buenas

twitteroauth.php

Código
  1. <?php
  2.  
  3. /*
  4.  * Abraham Williams (abraham@abrah.am) http://abrah.am
  5.  *
  6.  * The first PHP Library to support OAuth for Twitter's REST API.
  7.  */
  8.  
  9. /* Load OAuth lib. You can find it at http://oauth.net */
  10. require_once('OAuth.php');
  11.  
  12. /**
  13.  * Twitter OAuth class
  14.  */
  15. class TwitterOAuth {
  16.  /* Contains the last HTTP status code returned. */
  17.  public $http_code;
  18.  /* Contains the last API call. */
  19.  public $url;
  20.  /* Set up the API root URL. */
  21.  public $host = "https://api.twitter.com/1.1/";
  22.  /* Set timeout default. */
  23.  public $timeout = 30;
  24.  /* Set connect timeout. */
  25.  public $connecttimeout = 30;
  26.  /* Verify SSL Cert. */
  27.  public $ssl_verifypeer = FALSE;
  28.  /* Respons format. */
  29.  public $format = 'json';
  30.  /* Decode returned json data. */
  31.  public $decode_json = TRUE;
  32.  /* Contains the last HTTP headers returned. */
  33.  public $http_info;
  34.  /* Set the useragnet. */
  35.  public $useragent = 'TwitterOAuth v0.2.0-beta2';
  36.  /* Immediately retry the API call if the response was not successful. */
  37.  //public $retry = TRUE;
  38.  
  39.  
  40.  
  41.  
  42.  /**
  43.    * Set API URLS
  44.    */
  45.  function accessTokenURL()  { return 'https://api.twitter.com/oauth/access_token'; }
  46.  function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
  47.  function authorizeURL()    { return 'https://api.twitter.com/oauth/authorize'; }
  48.  function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
  49.  
  50.  /**
  51.    * Debug helpers
  52.    */
  53.  function lastStatusCode() { return $this->http_status; }
  54.  function lastAPICall() { return $this->last_api_call; }
  55.  
  56.  /**
  57.    * construct TwitterOAuth object
  58.    */
  59.  function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
  60.    $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
  61.    $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
  62.    if (!empty($oauth_token) && !empty($oauth_token_secret)) {
  63.      $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
  64.    } else {
  65.      $this->token = NULL;
  66.    }
  67.  }
  68.  
  69.  
  70.  /**
  71.    * Get a request_token from Twitter
  72.    *
  73.    * @returns a key/value array containing oauth_token and oauth_token_secret
  74.    */
  75.  function getRequestToken($oauth_callback) {
  76.    $parameters = array();
  77.    $parameters['oauth_callback'] = $oauth_callback;
  78.    $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
  79.    $token = OAuthUtil::parse_parameters($request);
  80.    $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
  81.    return $token;
  82.  }
  83.  
  84.  /**
  85.    * Get the authorize URL
  86.    *
  87.    * @returns a string
  88.    */
  89.  function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
  90.    if (is_array($token)) {
  91.      $token = $token['oauth_token'];
  92.    }
  93.    if (empty($sign_in_with_twitter)) {
  94.      return $this->authorizeURL() . "?oauth_token={$token}";
  95.    } else {
  96.       return $this->authenticateURL() . "?oauth_token={$token}";
  97.    }
  98.  }
  99.  
  100.  /**
  101.    * Exchange request token and secret for an access token and
  102.    * secret, to sign API calls.
  103.    *
  104.    * @returns array("oauth_token" => "the-access-token",
  105.    *                "oauth_token_secret" => "the-access-secret",
  106.    *                "user_id" => "9436992",
  107.    *                "screen_name" => "abraham")
  108.    */
  109.  function getAccessToken($oauth_verifier) {
  110.    $parameters = array();
  111.    $parameters['oauth_verifier'] = $oauth_verifier;
  112.    $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
  113.    $token = OAuthUtil::parse_parameters($request);
  114.    $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
  115.    return $token;
  116.  }
  117.  
  118.  /**
  119.    * One time exchange of username and password for access token and secret.
  120.    *
  121.    * @returns array("oauth_token" => "the-access-token",
  122.    *                "oauth_token_secret" => "the-access-secret",
  123.    *                "user_id" => "9436992",
  124.    *                "screen_name" => "abraham",
  125.    *                "x_auth_expires" => "0")
  126.    */  
  127.  function getXAuthToken($username, $password) {
  128.    $parameters = array();
  129.    $parameters['x_auth_username'] = $username;
  130.    $parameters['x_auth_password'] = $password;
  131.    $parameters['x_auth_mode'] = 'client_auth';
  132.    $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
  133.    $token = OAuthUtil::parse_parameters($request);
  134.    $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
  135.    return $token;
  136.  }
  137.  
  138.  /**
  139.    * GET wrapper for oAuthRequest.
  140.    */
  141.  function get($url, $parameters = array()) {
  142.    $response = $this->oAuthRequest($url, 'GET', $parameters);
  143.    if ($this->format === 'json' && $this->decode_json) {
  144.      return json_decode($response);
  145.    }
  146.    return $response;
  147.  }
  148.  
  149.  /**
  150.    * POST wrapper for oAuthRequest.
  151.    */
  152.  function post($url, $parameters = array()) {
  153.    $response = $this->oAuthRequest($url, 'POST', $parameters);
  154.    if ($this->format === 'json' && $this->decode_json) {
  155.      return json_decode($response);
  156.    }
  157.    return $response;
  158.  }
  159.  
  160.  /**
  161.    * DELETE wrapper for oAuthReqeust.
  162.    */
  163.  function delete($url, $parameters = array()) {
  164.    $response = $this->oAuthRequest($url, 'DELETE', $parameters);
  165.    if ($this->format === 'json' && $this->decode_json) {
  166.      return json_decode($response);
  167.    }
  168.    return $response;
  169.  }
  170.  
  171.  /**
  172.    * Format and sign an OAuth / API request
  173.    */
  174.  function oAuthRequest($url, $method, $parameters) {
  175.    if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
  176.      $url = "{$this->host}{$url}.{$this->format}";
  177.    }
  178.    $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
  179.    $request->sign_request($this->sha1_method, $this->consumer, $this->token);
  180.    switch ($method) {
  181.    case 'GET':
  182.      return $this->http($request->to_url(), 'GET');
  183.    default:
  184.      return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
  185.    }
  186.  }
  187.  
  188.  /**
  189.    * Make an HTTP request
  190.    *
  191.    * @return API results
  192.    */
  193.  function http($url, $method, $postfields = NULL) {
  194.    $this->http_info = array();
  195.    $ci = curl_init();
  196.    /* Curl settings */
  197.    curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
  198.    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
  199.    curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
  200.    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
  201.    curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
  202.    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
  203.    curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
  204.    curl_setopt($ci, CURLOPT_HEADER, FALSE);
  205.  
  206.    switch ($method) {
  207.      case 'POST':
  208.        curl_setopt($ci, CURLOPT_POST, TRUE);
  209.        if (!empty($postfields)) {
  210.          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
  211.        }
  212.        break;
  213.      case 'DELETE':
  214.        curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
  215.        if (!empty($postfields)) {
  216.          $url = "{$url}?{$postfields}";
  217.        }
  218.    }
  219.  
  220.    curl_setopt($ci, CURLOPT_URL, $url);
  221.    $response = curl_exec($ci);
  222.    $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
  223.    $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
  224.    $this->url = $url;
  225.    curl_close ($ci);
  226.    return $response;
  227.  }
  228.  
  229.  /**
  230.    * Get the header info to store.
  231.    */
  232.  function getHeader($ch, $header) {
  233.    $i = strpos($header, ':');
  234.    if (!empty($i)) {
  235.      $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
  236.      $value = trim(substr($header, $i + 2));
  237.      $this->http_header[$key] = $value;
  238.    }
  239.    return strlen($header);
  240.  }
  241. }
  242.  
  243.  

Es la clase para enviar el tweet junto con la OAuth.php
¡Gracias por la ayuda! :P

¡Saludos!
En línea

Mi algoritmo en PHP (estupideces y más).
Código
  1. while($Se_feliz){
  2.  Piensa_un_OBJETIVO(); // Sin excusas!
  3.  if($Tienes_un_objetivo){
  4.    Suspira(); // Sé paciente.
  5.    if($Consigues_el_objetivo){ echo "¡Felicidades #Aitor!";return;
  6.      //RETURN; ¿O volvemos a empezar?
  7.    }else{
  8.      Inténtalo_de_nuevo();
  9.    }
  10.  }
  11. }
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Info de un mail, desfase de horarios.
Dudas Generales
jamematen 0 1,712 Último mensaje 10 Mayo 2010, 10:42 am
por jamematen
[SOLUCIONADO] Planificador Semanal, Horarios, Días
Programación Visual Basic
VanHan 5 4,959 Último mensaje 26 Octubre 2010, 17:20 pm
por VanHan
Cómo funciona este keygen (aSc Horarios)
Ingeniería Inversa
hainner 1 62,655 Último mensaje 14 Agosto 2011, 04:53 am
por apuromafo CLS
Horarios de las escuelas de idiomas
Foro Libre
ion dissonance2 0 1,327 Último mensaje 7 Septiembre 2011, 18:33 pm
por ion dissonance2
Problemas conexion a servidor con batch y ejecutar una shell dentro del servidor
Scripting
andrespp 0 2,979 Último mensaje 13 Octubre 2011, 17:40 pm
por andrespp
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines