Jump to content

HELP with php


Akshay123

Recommended Posts

Hi

I am a total newb with php, and I have some code that I need to use, but isnt working for me.

Here it is:

 

<?php

include('/assets/UserAgentCheck/mobile_device_detect.php');

mobile_device_detect(true,true,true,true,true,true,false,false);

if($mobile==true){

  include('/m/index.html');

}else{

  include('/d.html');

}

exit;

?>

all the file paths are correct

the mobile_device_detect.php is supposed to detect a user agent, and return with a true or false indication right?

the (mobile_device_detect(true,true,true,true,true,true,false,false);) on line 3 is submitting imput to mobile_device_detect, which is required.

however, it doesnt matter what user agent i use, it always goes to /d.

Can someone help me?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/198041-help-with-php/
Share on other sites

and return with a true or false indication right?

 

Yes, but you are not catching the return value, look at your code:

 

mobile_device_detect(true,true,true,true,true,true,false,false);
if($mobile==true){    // $mobiles was not set anywhere

 

Use

 

$mobile = mobile_device_detect(true,true,true,true,true,true,false,false);

 

Link to comment
https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039161
Share on other sites

That would only work if register globals was enabled.  So, essentially, no.

 

You could provide a link somewhere on your page that allows people to switch between the versions, and pass a flag in your URL.

 

Something like..  ?switch=desktop

 

$switch = $_GET['switch'];
$mobile = ($switch == "desktop" && $mobile == TRUE) ? FALSE : TRUE;

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039186
Share on other sites

Wait, I'm confused

with the code you gave me, it would look like this for /index.php, right?

 

<?php
include('assets/UserAgentCheck/mobile_device_detect.php');
$mobile = mobile_device_detect(true,true,true,true,true,true,false,false);
if($mobile==true){
  include('/m/index.html');
}else{
  include('d.html');
}
exit;
$switch = $_GET['switch'];
$mobile = ($switch == "desktop" && $mobile == TRUE) ? FALSE : TRUE;
?>

so then if i understood that part, I would create a link in /m/index.html (my mobile page) pointing to http://localhost/?switch=desktop.

However when I do that, the server just ignored my query string. Just regular http://localhost/m/index.html showed up.

Link to comment
https://forums.phpfreaks.com/topic/198041-help-with-php/#findComment-1039201
Share on other sites

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.