Jump to content

[SOLVED] just woundering


Birdmansplace

Recommended Posts

i am wounder if its possible to have a redirect to another page if the first one times out or isn't there.  so say you go to www.yoursite.com/index.php and for some reason it doesn't load or isnt there it would take you to /index1.php?

 

If that makes any sence.  I am running a web site off my home connection and theres a few pages that some info i can't see cause of being hosted on another computer on my network and would like to see how the page looks and so on to the "world".  My index page loads an iframe from another computer on my network so to the world i have to open another port so...  and the only other way to do this from my knowledge is to make a second page the does everything localhost.

Link to comment
https://forums.phpfreaks.com/topic/141420-solved-just-woundering/
Share on other sites

Try this  ;D

<?php
$url = "http://www.doesnexist.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

$output = curl_exec($ch);
$info = curl_getinfo($ch);

if ($output === false || $info['http_code'] != 200)
{
header("Location: index.php");
}else{
header("Location: $url");
}
?>

you need to enable CURL,

create a php info page

<?php
phpinfo();
?>

 

open it and search for curl.. if you don't see it then enable it and restart apache

 

to enable curl

open php.ini

find

;extension=php_curl.dll

remove the ; so

extension=php_curl.dll

save restart apache

<?php
$url = "http://THIS IS WHERE I BUT LINK I WANT TO LOAD?";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

$output = curl_exec($ch);
$info = curl_getinfo($ch);

if ($output === false || $info['http_code'] != 200)
{
   header("Location: AND IF NOT FOUND PUT REDIRECT HERE?");
}else{
   header("Location: $url");
}
?>

 

i am kinda lost,

 

this is what i am doing

 

<iframe id="ListFrame" style="width:78%; height:250px;
border:1px" src="
<?php
$url = "http://http://www.webname.com:100/stats/server.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

$output = curl_exec($ch);
$info = curl_getinfo($ch);

if ($output === false || $info['http_code'] != 200)
{
   header("Location: http://192.168.x.xx/stats/server.php");
}else{
   header("Location: $url");
}
?>">
</iframe>

 

You can't have anything before a header.. so

try this

create a file called portal.php

 

<?php
$url = "http://http://www.webname.com:100/stats/server.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

$output = curl_exec($ch);
$info = curl_getinfo($ch);

if ($output === false || $info['http_code'] != 200)
{
   header("Location: http://192.168.x.xx/stats/server.php");
}else{
   header("Location: $url");
}
?>

 

then use that in the ifame

<iframe id="ListFrame" style="width:78%; height:250px;
border:1px" src="portal.php">
</iframe>

 

 

that should work

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.