[RESOLVED] need to port ASP to PHP
I have some really simple code that I need to port to PHP because a customer has a linux server and needs this code to run on it.
All the code does is check the USER_AGENT string sent by the browser to determine if the .NET framework is present. This info is ONLY sent in the USER_AGENT string if the webbrowser being used is IE, otherwise its not there.
So there are 3 possible outcomes.
1) User is using IE and .NET framework is present
2) User is using IE and .NET framework is NOT present
3) User is not using IE and .NET framework can not be determined
The code is not fool proof, but all it is supposed to do is give the user a suggestion on which of the 2 files they shoudl download, one that has the .NET framework (25+MB file) or the one that is just the program (~2MB file)
since the end users of this software are not computer savvy, this helps them to get the right one (and I would say 85% are using IE)
anyway, here is some of the ASP code so you can see the actual checks I am doing (basically just looking for keywords in the USER_AGENT string)
VB Code:
if instr(1, Request.ServerVariables("HTTP_USER_AGENT"), "1.1.4322") <> 0 or instr(1, Request.ServerVariables("HTTP_USER_AGENT"), "2.0.40607") <> 0 then
'WRITE OUT SOME HTML
elseif instr(1,Request.ServerVariables("HTTP_USER_AGENT"),"MSIE") <> 0 then
'WRITE OUT SOME HTML
else
'WRITE OUT SOME HTML
end if
I also call a sub that is in the same page
VB Code:
Sub DisplayDownloads(LargeFirst)
If LargeFirst then
'WRITE OUT SOME HTML
else
'WRITE OUT SOME HTML
end if
End Sub
Thanks!
Re: need to port ASP to PHP
Here you go
PHP Code:
if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") != false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") != false)
{
//stuff here
}
elseif(strpos($_SERVER['HTTP_USER_AGENT'],"MSIE") != false)
{
//stuff here
}
else
{
//stuff here
}
And
PHP Code:
function DisplayDownloads($LargeFirst)
{
if($LargeFirst)
{
//stuff here
}
else
{
//stuff here
}
}
Re: need to port ASP to PHP
thanks John.
I knew it was pretty simple, but since I don't do any PHP it would take me a bit longer to get all the syntax right and I am swamped at the moment..
I will take a look at this and post back with any further questions
Re: need to port ASP to PHP
I make a typo, just changed so if you tried it and it didn't work then that will be why.
Re: need to port ASP to PHP
no prob. I won't get around to making a mock up PHP page to test the code until later today
Re: need to port ASP to PHP
Quote:
Originally Posted by john tindell
Here you go
PHP Code:
if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") != false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") != false)
{
//stuff here
}
elseif(strpos($_SERVER['HTTP_USER_AGENT'],"MSIE") != false)
{
//stuff here
}
else
{
//stuff here
}
And
PHP Code:
function DisplayDownloads($LargeFirst)
{
if($LargeFirst)
{
//stuff here
}
else
{
//stuff here
}
}
You need to use !== as the strpos function can return if the string is found at the beginning at position; you've guessed it, 0. :)
PHP Code:
if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") !== false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") !== false)
{
//stuff here
}
Don't you also need to check for CRL / CLR in the useragent?
Re: need to port ASP to PHP
Quote:
Originally Posted by visualAd
You need to use !== as the strpos function can return if the string is found at the beginning at position; you've guessed it, 0. :)
PHP Code:
if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") !== false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") !== false)
{
//stuff here
}
Don't you also need to check for CRL / CLR in the useragent?
Its been a long couple of days :eek2:
Re: need to port ASP to PHP
well I know I am going to need to install PHP on my system to test this locally.
Is PHP easy to UNINSTALL if I decide later on that I do not want it on my system anymore?
Re: need to port ASP to PHP
also does PHP run on IIS? since that is the only dev web server install on my box
I am guessing yes, but you guys are the PHP pros ;)
Re: need to port ASP to PHP
Yes - technically you do not NEED to run the PHP installer. Just download the ZIP file off their site and extract it to a directory. You can either run PHP as an IIS ISAPI module or a CGI.
Which OS are you running on, the configuration is quite easy.
Re: need to port ASP to PHP
XP Pro SP2 is the one I was going to load it on. I have several PCs in the office (including a 2003 server machine) but for dev I would like to use the XP pro box.
Re: need to port ASP to PHP
I was able to install PHP5 and I got the code ported over and its working fine.
Thanks.
Re: [RESOLVED] need to port ASP to PHP
Great... now start porting all your other code. It'll be worth it. Promise :)
Re: [RESOLVED] need to port ASP to PHP
I do little code in ASP anymore.. I do everything new in ASP.NET
This was for some legacy code that needs to go on a clients own webserver, which is linux/php