|
-
May 31st, 2006, 10:22 AM
#1
[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!
-
May 31st, 2006, 10:56 AM
#2
<?="Moderator"?>
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
}
}
-
May 31st, 2006, 10:58 AM
#3
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
-
May 31st, 2006, 10:59 AM
#4
<?="Moderator"?>
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.
-
May 31st, 2006, 11:00 AM
#5
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
-
Jun 1st, 2006, 09:35 AM
#6
Re: need to port ASP to PHP
 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?
-
Jun 1st, 2006, 09:39 AM
#7
<?="Moderator"?>
Re: need to port ASP to PHP
 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
-
Jun 1st, 2006, 09:54 AM
#8
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?
-
Jun 1st, 2006, 09:55 AM
#9
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
-
Jun 1st, 2006, 10:16 AM
#10
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.
-
Jun 1st, 2006, 10:17 AM
#11
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.
-
Jun 2nd, 2006, 07:13 PM
#12
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.
-
Jun 2nd, 2006, 07:43 PM
#13
Re: [RESOLVED] need to port ASP to PHP
Great... now start porting all your other code. It'll be worth it. Promise
-
Jun 2nd, 2006, 08:50 PM
#14
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|