Selecionar imagen mas nombre aleatoriamente

  • Autor Autor JmGarciaYT
  • Fecha de inicio Fecha de inicio
J

JmGarciaYT

Curioso
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Hola, tengo un PHP con la api de twitter, que cuando una persona inicie sesión en mi web con la api de twitter, le de un nombre mas una foto aleatoriamente, pero que el nombre y la imagen coincidan

Imaginar que en el PHP tengo agregado 5 nombres (Manuel, antonio, lucia, bea y jose)

Entonces cuando una persona entre a la web quiero que ese php le de a una persona un nombre, da igual si es nombre de chica o chico.

Hasta aquí lo tengo yo, solo lo puse para explicarme mejor. yo ahora lo que quiero hacer es en el mismo PHP quiero que a cada nombre, se le añada una imagen, que cada nombre tenga una imagen, manuel una imagen, antonio, otra, etc, pero que coincidan, es decir, la foto de manuel, no puede aparecer a lucia, ni la foto de lucia a manuel

Si alguien es tan amable de ayudarme, pongo el PHP, puedo poner todos los archivos si hace falta

PHP:
<?php

if (is_dir('install') == true && file_exists('config.php') == true) {
    echo '<div class="container"><p>'
    . 'Borra ahora o renombra la carpeta install</div>';
} else if (is_dir('install') == true) {
    header("location: /install/");
} else {
    include('config.php');
    require_once('libs/twitteroauth/twitteroauth.php');
    include("libs/geoip/geoip.inc");
    include('classes/classTwitter.php');
$tw = new classTwitter();
if (isset($_SESSION['conectado']) && $_SESSION['conectado'] == 'ok') {
    if (isset($_GET['section'])) {
        $section = $_GET['section'];
        if ($section == 'conect') {
            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
            $request_token = $connection->getRequestToken(OAUTH_CALLBACK);
            $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
            $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
            switch ($connection->http_code) {
                case 200:
                    $url = $connection->getAuthorizeURL($token);
                    header('location:' . $url . '');
                    break;

                default:
                    echo 'Error';
            }
        } else {
            header('location: ' . $urlweb . '');
        }
    } elseif (isset($_GET['oauth_token'])) {

        $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
        $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
        $_SESSION['access_token'] = $access_token;
        if (200 == $connection->http_code) {
            $access_token = $_SESSION['access_token'];
            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
            $content = $connection->get('account/verify_credentials');
            $gi = geoip_open("libs/geoip/GeoIP.dat", GEOIP_STANDARD);
            $ip = $tw->GetIP();
            $token_cl = $_SESSION['access_token']['oauth_token'];
            $secret = $_SESSION['access_token']['oauth_token_secret'];
            $grupo = $_SESSION['access_token']['screen_name'];
            $tw->insertProfile($grupo, $token_cl, $secret, $content->followers_count, geoip_country_code_by_addr($gi, "$ip"));
            $_SESSION['conectado'] = 'ok';
            $listado = array('Miguel', 'Noelia', 'Beatriz', 'Álvaro', 'Pol', 'Meritxell', 'Laura', 'Cris', 'Fernando', 'Clara', 'Candelas', 'Pablo', 'Montse', 'Alain', 'Rodrigo', 'Adara', 'Bárbara', 'Jorge Javier Vázquez', 'Jordi González',);
            $prof = $listado[array_rand($listado)];
            $tweet = 'Dicen que me parezco a ' . $prof . '.de #GH17, descubre a que concursante te pareces en ' . $urlweb . 'app/';
            $_SESSION['resultado'] = 'Te pareces a: <span>' . $prof . '</span>';
            $connection->post('statuses/update', array('status' => utf8_decode(utf8_encode($tweet))));
            header('location: ' . $urlweb . '');
        } else {
            header('location: ' . $urlweb . '');
        }
    } else {
        include('views/viewContent.php');
    }
} else {

    if (isset($_GET['section'])) {
        $section = $_GET['section'];
        if ($section == 'conect') {
            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
            $request_token = $connection->getRequestToken(OAUTH_CALLBACK);
            $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
            $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
            switch ($connection->http_code) {
                case 200:
                    $url = $connection->getAuthorizeURL($token);
                    header('location:' . $url . '');
                    break;

                default:
                    echo 'Error';
            }
        } else {
            header('location: ' . $urlweb . 'app/');
        }
    } else {
        if (isset($_GET['oauth_token'])) {

            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
            $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
            $_SESSION['access_token'] = $access_token;
            if (200 == $connection->http_code) {
                $access_token = $_SESSION['access_token'];
                $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
                $content = $connection->get('account/verify_credentials');
                $gi = geoip_open("libs/geoip/GeoIP.dat", GEOIP_STANDARD);
                $ip = $tw->GetIP();
                $token_cl = $_SESSION['access_token']['oauth_token'];
                $secret = $_SESSION['access_token']['oauth_token_secret'];
                $grupo = $_SESSION['access_token']['screen_name'];
                $tw->insertProfile($grupo, $token_cl, $secret, $content->followers_count, geoip_country_code_by_addr($gi, "$ip"));
                $_SESSION['conectado'] = 'ok';
                $listado = array('Miguel', 'Noelia', 'Beatriz', 'Álvaro', 'Pol', 'Meritxell', 'Laura', 'Cris', 'Fernando', 'Clara', 'Candelas', 'Pablo', 'Montse', 'Alain', 'Rodrigo', 'Adara', 'Bárbara', 'Jorge Javier Vázquez', 'Jordi González',);
                $prof = $listado[array_rand($listado)];
                $tweet = 'Dicen que me parezco a ' . $prof . '.de #GH17, descubre a que concursante te pareces en ' . $urlweb . 'app/';
                $_SESSION['resultado'] = 'Te pareces a: <span>' . $prof . '</span>';
                $connection->post('statuses/update', array('status' => utf8_decode(utf8_encode($tweet))));
                header('location: ' . $urlweb . '');
            } else {
                header('location: ' . $urlweb . '');
            }
        } else {
                include('views/viewHeader.php');
                include('views/viewLanding.php');
                include('views/viewFooter.php');
            }
        }
    }
}
?>
 
Tu array del listado, hazlo algo como:
PHP:
$listado = array(
    array(
        'name' => 'Miguel',
        'img'  => 'ruta_de_imagen_de_migel.png',
    ),
    array(
        'name' => 'Noelia',
        'img'  => 'ruta_de_imagen_de_noelia.png',
    ),
    // ...
);

y ya cuando imprimas:
PHP:
$prof['name']
PHP:
$prof['img']

Saludos.
 
una solución extremadamente facil es que llames a las imagenes Miguel.jpg Pol.jpg y muestres la imagen que sea: NOMBRE.".jpg"
 
Atrás
Arriba