OK I have a great little scrip in PHP that lets me do some dynamic things based on peoples user agent, however I am having a bit of trouble figuring how to re-write this PHP using purely Miva Scrip, or how to include it so it executes properly.I recall that getting PHP to run in the HEAD is a bit problematic, but if it can be done that might be easier? I either need to get the PHP to run corectly in the HEAD section of MIVA pages or I need to rewrite it into Miva Script....The basics of the code are:$ua = $_SERVER['HTTP_USER_AGENT'];if ((preg_match('what I am looking for in the user agent', $ua)){ $user = "what I will test for latter to decide what to do";} else if ((preg_match('what I am looking for in the user agent', $ua)){ $user = "something else I will test for latter to decide what to do";} I also make use of the "||" or, "&&" and, and or the "!" not operators in these if else teststhen I runif ($user == "a value I set to test for"){ print "the HTML I want";}else if ($user == "another value I set to test for"){ print "the HTML I want";}any help I can get converting this PHP to MIVA or running this PHP in MIVA is much appreciated. I am basically getting caught up on properly passing the variable between to tests and how to execute preg_match() and $_SERVER['HTTP_USER_AGENT'] in Miva Script, or how to get these PHP instructions to properly execute if included in the HEAD section of a miva page. Either solution would work in this case.Thanks a million in advance.
Announcement
Collapse
No announcement yet.
PHP to Miva Scrip need some help
Collapse
X
-
Re: PHP to Miva Scrip need some help
OK I have a great little scrip in PHP that lets me do some dynamic things based on peoples user agent, however I am having a bit of trouble figuring how to re-write this PHP using purely Miva Scrip, or how to include it so it executes properly.I recall that getting PHP to run in the HEAD is a bit problematic, but if it can be done that might be easier? I either need to get the PHP to run corectly in the HEAD section of MIVA pages or I need to rewrite it into Miva Script....The basics of the code are:$ua = $_SERVER['HTTP_USER_AGENT'];if ((preg_match('what I am looking for in the user agent', $ua)){ $user = "what I will test for latter to decide what to do";} else if ((preg_match('what I am looking for in the user agent', $ua)){ $user = "something else I will test for latter to decide what to do";} I also make use of the "||" or, "&&" and, and or the "!" not operators in these if else teststhen I runif ($user == "a value I set to test for"){ print "the HTML I want";}else if ($user == "another value I set to test for"){ print "the HTML I want";}any help I can get converting this PHP to MIVA or running this PHP in MIVA is much appreciated. I am basically getting caught up on properly passing the variable between to tests and how to execute preg_match() and $_SERVER['HTTP_USER_AGENT'] in Miva Script, or how to get these PHP instructions to properly execute if included in the HEAD section of a miva page. Either solution would work in this case.There that should be easier for people to actually read. Thanks a million in advance.
-
Re: PHP to Miva Scrip need some help
OK I have a great little scrip in PHP that lets me do some dynamic things based on peoples user agent, however I am having a bit of trouble figuring how to re-write this PHP using purely Miva Scrip, or how to include it so it executes properly.
I recall that getting PHP to run in the HEAD is a bit problematic, but if it can be done that might be easier? I either need to get the PHP to run corectly in the HEAD section of MIVA pages or I need to rewrite it into Miva Script....
The basics of the code are:
I also make use of the "||" or, "&&" and, and or the "!" not operators in these if else testsPHP Code:$ua = $_SERVER['HTTP_USER_AGENT'];
if ((preg_match('what I am looking for in the user agent', $ua))
{
$user = "what I will test for latter to decide what to do";
}
else if ((preg_match('what I am looking for in the user agent', $ua))
{
$user = "something else I will test for latter to decide what to do";
}
then I run
any help I can get converting this PHP to MIVA or running this PHP in MIVA is much appreciated. I am basically getting caught up on properly passing the variable between to tests and how to execute preg_match() and $_SERVER['HTTP_USER_AGENT'] in Miva Script, or how to get these PHP instructions to properly execute if included in the HEAD section of a miva page. Either solution would work in this case.PHP Code:if ($user == "a value I set to test for")
{
print "the HTML I want";
}
else if ($user == "another value I set to test for")
{
print "the HTML I want";
}
There that should be easier for people to actually read. Thanks a million in advance.
Comment
-
Re: PHP to Miva Scrip need some help
You could do this easily with actual mivascript
<mvif expr="{ 'WHAT YOU ARE LOOKING FOR IN USER AGENT' IN toupper(s.user_agent) }">
do this
<mvelseif expr="{ 'SOMETHING ELSE YOU ARE LOOKING FOR' IN toupper(s.user_agent) }">
do something else
<mvelse>
do the last thing
</mvif>
Do actually do it in a template, you'd need toolkit or toolbelt (and i don't know the syntax, but the Gist is the same).
Here's a complete list of system variables:
http://www.mivascript.com/topic/system-variables.htmlBruce Golub
Phosphor Media - "Your Success is our Business"
Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
phosphormedia.com
Comment
-
Re: PHP to Miva Scrip need some help
ok so something like:
would become:PHP Code:else if ((preg_match('/iPad/i', $ua)) || (preg_match('/tablet/i', $ua)))
{
/* This user agent is on a tablet */
$user = "result1";
}
For my sanity making sure I am following the syntax correctly. Now if posible I would like to just be able to add the code like wise to the template so I guess I need to get familiar with the different syntax needed for toolkit or toolbelt should I contue on that here in this post or start a new one for the toolkit or tool belt side of this. I want to do both as I would like to add this functionality as a module so others can add it to any MIVA store with out the need to understand the functions, but for more advanced uses need to know how to likewise just add the functions directly to the template.Code:<mvelseif expr="{ '/iPad/i' IN toupper(s.user_agent) || '/tablet/i' IN toupper(s.user_agent) }"> <MvASSIGN NAME="g.User" VALUE="result1">
Comment
-
Re: PHP to Miva Scrip need some help
Close: "||" is OR in mivascript.
<mvelseif expr="{ '/iPad/i' IN toupper(s.user_agent) || '/tablet/i' IN toupper(s.user_agent) }">
<MvASSIGN NAME="g.User" VALUE="result1">
To use mivascript, you'd have to create a module (by following the Module API doc and asking tons of questions which are not answered by that do (and of course, get and install the compiler). But yea, can be done.
Another thing you could do is use the PHP to 'redirect' the customer by having that as the default "landing" page, using PHP code to do the detection, then, send them to either "merchant.mv?screen=XXXX&restof=merchant&variables =intheurlBruce Golub
Phosphor Media - "Your Success is our Business"
Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
phosphormedia.com
Comment
-
Re: PHP to Miva Scrip need some help
Ya I am noticing a lack of compete documentation but to get the functionality I have with the PHP scrip I need to get this done. Unfortunately simple redirects would not work. As content is dynamic genrated based on user agent. If I did redirects would need to make 50 ver of each page just not practical to manage. I am confused on the whole || Vs OR thing are you saying I should use "OR" instead of ||. I ask because the code you posed is identical to what I wrote as far as I can see.Originally posted by Bruce - PhosphorMedia View PostClose: "||" is OR in mivascript.
<mvelseif expr="{ '/iPad/i' IN toupper(s.user_agent) || '/tablet/i' IN toupper(s.user_agent) }">
<MvASSIGN NAME="g.User" VALUE="result1">
To use mivascript, you'd have to create a module (by following the Module API doc and asking tons of questions which are not answered by that do (and of course, get and install the compiler). But yea, can be done.
Another thing you could do is use the PHP to 'redirect' the customer by having that as the default "landing" page, using PHP code to do the detection, then, send them to either "merchant.mv?screen=XXXX&restof=merchant&variables =intheurl
Comment
-
Re: PHP to Miva Scrip need some help
Yes, the mivascript command for || is OR.
if you haven't seen this already, its handy to have around: http://www.mivascript.com/Bruce Golub
Phosphor Media - "Your Success is our Business"
Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
phosphormedia.com
Comment
Comment