Jump to content

[SOLVED] include on another domain


saint959

Recommended Posts

Hi Guys,

 

I have been sitting with the below problem and i have tried all i think i can of :)

 

Here is what i am trying to do:

 

there are two websites, one managed by me and the other not.

 

I need to send the web master of the other site a script which checks what device is visiting his website, if it is a cell phone then redirect the user to the mobile website on my server but i dont want to send him the "source" of the function, instead jsut some code for him to add to the top of his site before any headers are sent.

 

What i have done so far is below:

 

Script on Client Server:


<? 
$cp ="web";
$ht_us = urlencode($_SERVER['HTTP_USER_AGENT']);
$ht_acc = urlencode($_SERVER['HTTP_ACCEPT']);
$xw_prof = urlencode($_SERVER['HTTP_X_WAP_PROFILE']);
$profile = urlencode($_SERVER['HTTP_PROFILE']);
$mini = urlencode($_SERVER['X-OperaMini-Features']);
$pix = urlencode($_SERVER['UA-pixels']);

include "http://www.site.co.za/redirect/site_redirect.php?cp=$cp&ht_us=$ht_us&ht_acc=$ht_acc&xw_prof=$xw_prof&profile=$profile&mini=$mini&pix=$pix"; 

?>

 

 

The include file on my server: (site_redirect.php)

 


<?php
$cp = $_GET['cp'];

function detect_mobile_device(){

$ht_us = urldecode($_GET['ht_us']);
$ht_acc = urldecode($_GET['ht_acc']);
$xw_prof = urldecode($_GET['xw_prof']);
$profile = urldecode($_GET['profile']);
$mini = urldecode($_GET['mini']);
$pix = urldecode($_GET['pix']);

// check if the user agent gives away any tell tale signs it's a mobile browser, the code that goes here is working perfectly because i have used it in tons of other places
if (mobile) return true

}

if(detect_mobile_device())
{
header('Location: http://www.site.co.za');
//print "<meta http-equiv='refresh' content='0;URL=http://www.site.co.za'>"; 
}

?>

 

the ideal solution would be that the included file would send the user to my domain automatically with any delays, instead what is happening is the file that the user should be sent to is being "imported" into the main website of the client.

 

here is the code as on the server. we have a number of servers so the include file is on another server. (because im testing from my computer i have changed the if statement in the included file to ! i.e. !detect_mobile_device() just for testing)

 

http://www.cellsurveys.co.za/test.php

 

I hope this makes sense to someone :)

Link to comment
Share on other sites

Simple - don't do an include. Insead put the redirect in the "client" code based upon a response from the script on your server. Your page should be a sijmple PHP page that returns true or false. Here is some code (not tested) that should point you int he right direction:

 

Script on Client Server:

<?php

$cp ="web";
$ht_us = urlencode($_SERVER['HTTP_USER_AGENT']);
$ht_acc = urlencode($_SERVER['HTTP_ACCEPT']);
$xw_prof = urlencode($_SERVER['HTTP_X_WAP_PROFILE']);
$profile = urlencode($_SERVER['HTTP_PROFILE']);
$mini = urlencode($_SERVER['X-OperaMini-Features']);
$pix = urlencode($_SERVER['UA-pixels']);

$source_page = "http://www.site.co.za/redirect/site_redirect.php?cp=$cp&ht_us=$ht_us&ht_acc=$ht_acc&xw_prof=$xw_prof&profile=$profile&mini=$mini&pix=$pix";
$mobile = file_get_contents($source_page);

if ($mobile=='1') {
    header('Location: http://www.site.co.za');
}

?>

 

The PHP page on you server:

<?php

$cp = $_GET['cp'];

function detect_mobile_device(){

    $ht_us = urldecode($_GET['ht_us']);
    $ht_acc = urldecode($_GET['ht_acc']);
    $xw_prof = urldecode($_GET['xw_prof']);
    $profile = urldecode($_GET['profile']);
    $mini = urldecode($_GET['mini']);
    $pix = urldecode($_GET['pix']);

    // check if the user agent gives away any tell tale signs
    // it's a mobile browser the code that goes here is working
    // perfectly because i have used it in tons of other places
    if (mobile)  return true;
}

//Output 1 or 0 to indicate if it is a mobile device
if(detect_mobile_device()) { echo '1'; }
else { echo '0'; }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.