Jump to content

MIME Error with Feed


Recommended Posts

I am facing some difficulty with integrating the feed output into an HTML page. Please let me know what I'm doing wrong.

Test page to display domain pricing table: https://www.outpowerhosting.com/portal/domain-test2.html

Error: Refused to execute script from 'https://www.outpowerhosting.com/portal/feeds/domainpricing.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

My htaccess file already has the following:

<IfModule mime_module>
  AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>

 

Link to comment
Share on other sites

On 3/11/2018 at 5:28 PM, brian! said:

I assume you have fixed this, because the page seems to be working fine now. :idea:

Sorry, my reply was approved much later than your post. Please see my above post on how I got it to work.

Also, I had to modify the domainpricing.php code as shown below so that it accepts ?currency= in the URL string to return the data based on currency.

Quote

if (!is_numeric($currency)) {
    $currency = array();
} else {
    $currency = getCurrency('', $currency);
    $currency = ($currency) ? getCurrency('',$currency) : getCurrency();
}

 

Now, here's where I ne

ed some help. I have my custom HTML pages for our main website that is outside of the WHMCS system. I want the user to select a currency from a drop down, the page will refresh and based on which selection user made, that particular type of feed string will be executed. For example, if user selects currency 1, the feed string for the domainpricing table script should have ?currency=1 appended to the end of the src value. I've been stuck at this part for the last 2 days.

This is my sample test dropdown code:

<div>
  <select id="CurrV" onchange="getCurrV(this)">
    <option selected="selected">Change Currency</option>
    <option value="1">INR</option>
    <option value="2">USD</option>
    <option value="3">EUR</option>
  </select>
</div>

 

Here are the scenarios I have considered in trying to build this.

-------------------------------------------------------------------------------

1. User selects a currency from dropdown, the value is picked by Javascript and then processes an if statement that checks value of variable and then selects the preformed src script eg: 

if (xyz == 1)	{
		<script type="text/javascript" src="portal/feeds/domainpricing.php?currency=1"></script>
}else if (xyz == 2) {
  <script type="text/javascript" src="portal/feeds/domainpricing.php?currency=2"></script>
}else
  <script type="text/javascript" src="portal/feeds/domainpricing.php?currency=3"></script>
}}}

This is obviously not going to work because I can't have a script inside a script. I have tried other ways to get the script generated using variable assigning and appending etc. but that doesn't seem to execute although the if logic is working.

-------------------------------------------------------------------------------

2. The other method I have tried holds more promise. in this method, I have the value that is fetched from the drop down and then appended to the 'src' of the script. This is precisely where I am stuck at. i.e couldn't find a logic/method to have it appended to the static src value.

<script>
    function getCurrV(curr)
    {
    var curvalue = curr.value;
    //console.log(curvalue);
    var url_now = "https://www.outpowerhosting.com/domain-test.html";
    //console.log(url_now)
    var url_new = url_now + '?currency=' + curvalue;
    //console.log(url_new)
    window.location = url_now + '?currency=' + curvalue;
    //var feed_link = "portal/feeds/domainpricing.php" + '?currency=' + curvalue;
    //console.log(feed_link);
       
   
   <script type="text/javascript" src='feed_link'></script> /* This is where I need help */
     
           }
   </script>  

Again, the above code is for concept demonstration purposes only, I realize you can't just pass the variable feed_link in the src or have a script inside a script. I have tried several different methods of trying to have the script line generated dynamically but have failed.

What I would like help with is, if someone could tell me if the current methods are possible, and if yes, any direction would be helpful. Also, is there a better way to pass the currency value to the domainpricing.php file without resorting to hacking the src attribute?

Thanks in advance.

Link to comment
Share on other sites

On 3/12/2018 at 12:29, Outpower Hosting said:

Now, here's where I need some help. I have my custom HTML pages for our main website that is outside of the WHMCS system. I want the user to select a currency from a drop down, the page will refresh and based on which selection user made, that particular type of feed string will be executed. For example, if user selects currency 1, the feed string for the domainpricing table script should have ?currency=1 appended to the end of the src value. I've been stuck at this part for the last 2 days

if it were me, i'd have used js to change the url via the dropdown, and then used PHP to add the currency value to the feed URL...

<select id="currency_select">
  <option value="">Change Currency</option>
  <option value="?currency=1">INR</option>
  <option value="?currency=7">USD</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
    $(function(){
      $('#currency_select').on('change', function () {
          var url = $(this).val();
          if (url) {
              window.location = url;
          }
          return false;
      });
    });
</script>
<script type="text/javascript" src="https://www.outpowerhosting.com/portal/feeds/domainpricing.php?currency=<? echo intval($_GET['currency']); ?>"></script>

cQnpmBt.pngRIF17rE.png

using .php instead of .html would give you so many more options when it comes to coding (especially with js inside js feeds).... so in the above example, the file has a .php extension rather than .html.

also, rename the domainpricing.php feed file to something else because the next time you do a WHMCS update, it will be overwritten - certainly by the automatic updater... and manually too if you're not careful.

On 3/12/2018 at 12:29, Outpower Hosting said:

Also, is there a better way to pass the currency value to the domainpricing.php file without resorting to hacking the src attribute?

there would be other ways, but I don't think any of them are necessarily better than just passing the currency value in the URL.

I mean you could use the dropdown to go to specific URLs, with each selection using a different feed with a unique currency hardcoded within it... that removes the need for reading the currency value, but then you have multiple files to maintain... which is a little silly. :)

Link to comment
Share on other sites

14 minutes ago, brian! said:

if it were me, i'd have used js to change the url via the dropdown, and then used PHP to add the currency value to the feed URL...

.using .php instead of .html would give you so many more options when it comes to coding (especially with js inside js feeds).... so in the above example, the file has a .php extension rather than .html.

 

Thank you! You're a life saver! Test Page has been updated: https://www.outpowerhosting.com/domain-test.php

I was actually hoping and praying that I do not have to go the PHP way because now matter how many optimizations, it still comes no where close to the load speeds for an HTML page. I was also thinking if I go PHP, it would be better to go with WordPress and something like WHMPress plugin for all the additional features but again WP was something I was trying to avoid for ease of maintenance and speed.

One other question I did have was, if I have to maintain/store this variable value as the customer goes across all pages, do I just need an additional JS to check the window.url and modify if needed i.e outside of the onchage function apart from storing the variable that is?

Another thing that I would like an opinion on is: Let's say I keep the page .html and add the below to htaccess, will it be still faster than a full file being processed as PHP or do you think the PHP processor will take the exact same time to load the page as  a full .php page? I'm running some benchmarks to see this for myself now.

AddType application/x-httpd-php .html
Link to comment
Share on other sites

6 hours ago, Outpower Hosting said:

I was actually hoping and praying that I do not have to go the PHP way because now matter how many optimizations, it still comes no where close to the load speeds for an HTML page. I was also thinking if I go PHP, it would be better to go with WordPress and something like WHMPress plugin for all the additional features but again WP was something I was trying to avoid for ease of maintenance and speed.

you can mix and match.... use .html for your pages, and only when necessary, switch to using .php - I don't know your plans, but if you can get away with doing what you need in .html and are happy with that, then there's no need to change everything to using .php

I don't think your customers are going to care if some pages are .php and some .html.... in any event, all of WHMCS is going to be using .php and you can't get around that.

6 hours ago, Outpower Hosting said:

One other question I did have was, if I have to maintain/store this variable value as the customer goes across all pages, do I just need an additional JS to check the window.url and modify if needed i.e outside of the onchange function apart from storing the variable that is?

hmm... you could pass the currency value in links from the above test page and if the receiving page was setup to check for the value, then you could continue to use the same currency... if you can do that in JS, then you might be able to get away with not using .php... though every simple solution I can think of to do this involves using PHP... even if you used a Geo-IP solution to locate the customer (e.g if in India, use curr 1 else curr 7), that would probably require PHP too.

6 hours ago, Outpower Hosting said:

Another thing that I would like an opinion on is: Let's say I keep the page .html and add the below to htaccess, will it be still faster than a full file being processed as PHP or do you think the PHP processor will take the exact same time to load the page as  a full .php page? I'm running some benchmarks to see this for myself now.

almost certainly what will slow the test page down most is the data feeds... it's not going to matter much whether it's a html or php file, it will be the fetching of the data that will be the biggest slowdown.

something that I should add in passing, in case you are unaware, but once they have ordered previously, WHMCS customers can't order in a different currency... so if they order in USD, once logged in to WHMCS, they will only see USD pricing (or products priced in USD)... they won't see INR pricing... obviously once they leave WHMCS and you can't identify who they are, they'll be able to see both your INR and USD pricing on these HTML pages... now that may be a good or bad thing for you, but I thought it worth mentioning.

Link to comment
Share on other sites

How do I make the /feeds/domainchecker.php output without the .(dot) before the domain extensions and yet be able to pass the info the WHMCS backend correctly? Right now, the drop down list of domain extensions are all with the (dot) before them, hence makes searchability an issue as the user has to press (dot) before typing in the first letter of the extension they are looking for. Not all users will be smart enough to figure this and for example if they are searching for .org domain and they just hit 'o' in the drop down list, nothing happens making them think the alphabetic search doesn't work within the drop down?

Link to comment
Share on other sites

19 hours ago, Outpower Hosting said:

How do I make the /feeds/domainchecker.php output without the .(dot) before the domain extensions and yet be able to pass the info the WHMCS backend correctly? Right now, the drop down list of domain extensions are all with the (dot) before them, hence makes searchability an issue as the user has to press (dot) before typing in the first letter of the extension they are looking for. Not all users will be smart enough to figure this and for example if they are searching for .org domain and they just hit 'o' in the drop down list, nothing happens making them think the alphabetic search doesn't work within the drop down?

you could change...

    $code .= '<option>'. htmlspecialchars(tld, ENT_QUOTES, 'UTF-8') . '</option>';

to...

    $code .= '<option>'. htmlspecialchars(substr($tld, 1), ENT_QUOTES, 'UTF-8') . '</option>';

and that will remove the . from the dropdown but still send the correct TLD to the cart. :idea:

S8ur76W.png

Link to comment
Share on other sites

21 minutes ago, brian! said:

 


    $code .= '<option>'. htmlspecialchars(substr($tld, 1), ENT_QUOTES, 'UTF-8') . '</option>';

and that will remove the . from the dropdown but still send the correct TLD to the cart. :idea:

 

Purrrfect!! :1_grinning:

Just to add, I had to bring the (dot) outside/before, so added the below line into the first $code just before the <select> tag.

<font color="#fff" size="4px">. </font>

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated