PHP code doesnt work on Android and IOS Phone's Browser

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

wizzkid
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Mar 18, 2012 9:09 pm

PHP code doesnt work on Android and IOS Phone's Browser

Postby wizzkid » Mon Aug 04, 2014 1:54 am

Hi Guys,

I am working on the code for my small site/ captive portal. It works on the PC , but it doesnt work on Android mobile phones.

Code: Select all

  <tr>
<?php
      $base_grant_url = urldecode($_GET['base_grant_url']);
      $user_continue_url = urldecode($_GET['user_continue_url']);
      $override_continue_url = 'http://www.yahoo.com';
     
      $override_the_users_request = false;
      if ($override_the_users_request) {
        $grant_url = $base_grant_url . "?continue_url=" . urlencode($override_continue_url) ;
      } else {
        $grant_url = $base_grant_url . "?continue_url=" . urlencode($user_continue_url);
      }

      // The following parameters may be used for tracking purposes. They are not necessary for authentication.
      $node_id = urldecode($_GET['node_id']);
      $gateway_id = urldecode($_GET['gateway_id']);
      $client_ip = urldecode($_GET['client_ip']);
    ?>

    <td align="center"><a href="<?php print $grant_url ?>" target="_blank" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','asset_m/Button hover-ContinuetoInternet.png',1)"><img class="scale-with-grid" src="asset_m/Button-ContinuetoInternet.png" width="40%" height="40%" id="Image5"></a></td>
  </tr>


I hope somebody will step in and help me solve the issue.

Thanks.

landi
php-forum Active User
php-forum Active User
Posts: 311
Joined: Thu Mar 15, 2012 3:59 pm

Re: PHP code doesnt work on Android and IOS Phone's Browser

Postby landi » Mon Aug 04, 2014 9:07 am

That's a lot of code. Which bit "doesn't work"?

Browsers on phones may be different to PC, but they work much the same, and lots of phones run standard html/javascript without problems. I suggest you minimise the problem to a line or two of code that "doesn't work", then show us the line and tell us what you expect it to do, and what it actually does.
-A

wizzkid
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Mar 18, 2012 9:09 pm

Re: PHP code doesnt work on Android and IOS Phone's Browser

Postby wizzkid » Tue Aug 05, 2014 5:56 am

Hi Landi and ALL,

Sorry, I will paste a shorten code.

Code: Select all


<?php
      $base_grant_url = urldecode($_GET['base_grant_url']);
      $user_continue_url = urldecode($_GET['user_continue_url']);
      $override_continue_url = 'http://www.yahoo.com';
     
      $override_the_users_request = false;
      if ($override_the_users_request) {
        $grant_url = $base_grant_url . "?continue_url=" . urlencode($override_continue_url) ;
      } else {
        $grant_url = $base_grant_url . "?continue_url=" . urlencode($user_continue_url);
      }
?>
<a href="<?php print $grant_url ?></a>



Basically, the code will get the users current URL and print on href.

user_continue_url - is what the users are browsing or intend to browse (continue_url=http://google.com)
base_grant_url -is the captive portal URL. (https://n25.network-auth.com/splash/grant? - where the system will generate)

When click, the link should look like:
https://n25.network-auth.com/splash/gra ... google.com

Usage of above code: This will be for a Cisco Meraki Captive Portal page with "Connect to Internet" button (which is the href="<?php print $grant_url ?>")

The Issue: As far as I can see the issue is in urldecode and urlencode . I think Android and IOS doesnt understand it.

Any suggestion ?


Thanks.

landi
php-forum Active User
php-forum Active User
Posts: 311
Joined: Thu Mar 15, 2012 3:59 pm

Re: PHP code doesnt work on Android and IOS Phone's Browser

Postby landi » Tue Aug 05, 2014 6:23 am

Sorry, it is difficult for me to understand. I think language may be the barrier.

I suggest the following:
1) Remove the functions urlencode() and urldecode() and see if the page works.

2) The url you posted does not generate ANY output (view source is blank). I think you have a problem somewhere else in the file. Try printing out the values of your variables e.g.

Code: Select all

     
    $base_grant_url = urldecode($_GET['base_grant_url']);
    print "$base_grant_url =" . $base_grant_url . '<br>';
    $user_continue_url = urldecode($_GET['user_continue_url']);
    print "$user_continue_url =" . $user_continue_url . '<br>';
    $override_continue_url = 'http://www.yahoo.com';
    print "$override_continue_url =" . $override_continue_url . '<br>';


3. Post a very simple COMPLETE page like this so we can see the whole page and the results:

Code: Select all

<html><head><title>test</title></head>
<body>
<?php
      $base_grant_url = urldecode($_GET['base_grant_url']);
      $user_continue_url = urldecode($_GET['user_continue_url']);
      $override_continue_url = 'http://www.yahoo.com';

      $grant_url = $base_grant_url . "?continue_url=" . urlencode($user_continue_url);
?>
Hello World
<a href="<?php print $grant_url ?>">Link</a>
Goodbye World
</body>
</html>


hope that helps
-A

wizzkid
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Mar 18, 2012 9:09 pm

Re: PHP code doesnt work on Android and IOS Phone's Browser

Postby wizzkid » Tue Aug 05, 2014 10:48 pm

Hi Landi,

Very sorry. I am from Philippines. :-)

Anyways, I already know where the issue, the page is being forwarded once / twice that is why the code wasnt able to get the correct URL.

Here's a backgrounder.
1. When a person view a website, I have script that detects whether they are using Android , IOS then
2. It will redirect to file called index-ma.php

If OS Android
- index-ma.php
If OS IOS
- index-mi.php
If screen size < 699
- index-m.php

this is where the issue is, when the index file forward the user to say index-ma.php.

Question: Is there a way to get the previous URL using decode?

in linux term = " ../../../ "


Thanks.

landi
php-forum Active User
php-forum Active User
Posts: 311
Joined: Thu Mar 15, 2012 3:59 pm

Re: PHP code doesnt work on Android and IOS Phone's Browser

Postby landi » Wed Aug 06, 2014 2:28 am

Hi wizzkid,

In linux, ".." refers to a higher level of directory in the SAME context as the file. I think you are trying to get the previous URL, which is a DIFFERENT content. (BTW, you can of course use .. in a url. E.g. ../index-ma.php will look for index-ma.php in a directory above the current page, but I think this is not what you are asking).

The change of context is what makes your problem difficult because each page does not know anything about the previous page except:

1) You can try $_SERVER['HTTP_REFERRER'] to see if the calling/previous page left its name. This is browser dependent and is more useful for search tracking than for your application.

2) You could pass the context in the url e.g.
If OS Android
- index-ma.php?called_from=xyz

3) You can preserve context between pages using sessions. You can use cookies to store a session id - see php session_start() - or you can pass a session id in the url, but then you need some code to convert the session id to a list of values you want to preserve. One way to do this is to use a database table and the session id is the key.

-A

wizzkid
New php-forum User
New php-forum User
Posts: 8
Joined: Sun Mar 18, 2012 9:09 pm

Re: PHP code doesnt work on Android and IOS Phone's Browser

Postby wizzkid » Wed Aug 06, 2014 6:54 pm

Thanks, Landi. #3 is what I am thinking since lastnight to solve this issue. :)

Appreciate your inputs ..

Many Thanks :)


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest