Jump to content

Asp Or Php


johnnyg24

Recommended Posts

I would like to know, before I start to learn another scripting language, whether I should use ASP or PHP or maybe even a different one. Here is what I need to accomplish. Our computer system at work uses a Windows platform to run jBase, a multivalued Pick operating system. We currently use WebWizard to build our dynamic web pages but this has its limitations. WebWizard enable us to build some web pages, gather user input and run BASIC programs to retrieve information from our database and display it back to the customer.I would like to be able to create product search pages and shopping carts for our website. I was able to use xml and js for a product search page, but we have too many products with too much information that the xml data took too long to load and customers wouldn't use it. For the shopping cart, using xml data is never accurate when it comes to stock levels because they are always changing and the data is basically "stale" the moment we create it.I would also like to create online account that can set personal preference, such as email options or product updates. With all this in mind, I would need to do what our WebWizard program is doing which would be gathering user input, and extract data or even modify data from our database and display it back to the customer. I have a good background in HTML and XML and a small background in js. Any suggestions where I should start?

Link to comment
Share on other sites

Either technology can do what you want to do if you want to do it all stand-alone. If you need to interface with another system, like jBase, it will probably be worth it to do some research and compare the support in PHP and ASP.net for something like jBase. Figure out how jBase is able to communicate with other programs and see if PHP or ASP.net supports it better.

Link to comment
Share on other sites

There are several differences. If you only want one, I would say the major difference is that ASP and ASP.net are Microsoft technologies, and PHP is an open source project. Most of the other differences come because of those.SQL isn't related to ASP or PHP, it doesn't replace them. SQL is the language that most databases understand. ASP and PHP are server-side processing languages. Most large web applications these days use databases to store their data, so most applications use SQL commands to interact with the database.

Link to comment
Share on other sites

What is the major difference between ASP and PHP?Also, should SQL be something to look at as an option?
Consider also other things you're going to chose beside the server side language. As an example PHP can be insalled in both windws and linux, IIS and Apache, ASP only on Bill's stuff!!!
Link to comment
Share on other sites

  • 1 month later...

ASP already is deprecated. They're similar, but the .net framework is pretty different than anything ASP classic had. Both of them are similar in that ASP and ASP.net are not actually languages, they're sort of like a platform or API that you use another language to program with. When I write ASP code, for example, I write all my code using Javascript. Here's my ASP code to increment a counter in a text file, for example:

<% @LANGUAGE="Jscript" %><%var FSobj = new ActiveXObject("Scripting.FileSystemObject");var readfile = FSobj.OpenTextFile("E:\\Inetpub\\wwwroot\\domain.com\\webcontent\\00_root\\homepage\\moviecounter.txt", 1);var current = readfile.ReadLine();readfile.Close();current = parseInt(current);if (isNaN(current))  current = 0;current++;var writefile = FSobj.OpenTextFile("E:\\Inetpub\\wwwroot\\domain.com\\webcontent\\00_root\\homepage\\moviecounter.txt", 2);		writefile.Write(current);writefile.Close();%>

Most ASP examples are given in VBScript, but I hate pretty much everything about VB. When I write ASP.net code, I usually use C# for that, but there are a ton of languages you can use with .net in general.

Link to comment
Share on other sites

Note that there are a number of PHP frameworks available if that's a plus. CodeIgniter for example, they're not quite traditional MVC, but they get the job done. If you want a framework you should investigate the choice PHP has.

Link to comment
Share on other sites

  • 2 weeks later...

I read with interest this thread about ASP or PHP. I got here since I opted to not to study Microsoft's ASP in preference to the open source PHP, and since I understood that I could do pretty much the same things in either one or the other. Accordingly, I DID study the PHP tutorial and feel I understood it well enough for the examples that were shown there.Since I read this thread, I'm even more happy that I did not commit myself to ASP, since it is now deprecated and one must study ASP.net instead to be contemporary, which makes it a much more intensive undertaking, especially if I can get what I need from open-sourced PHP.Last, I'm a Linux user and love open source everything (well, if I can find what I need in open source, that is).I'm now in my 17th w3schools basics-through-advanced tutorial (HTML, XHTML, CSS, SQL, PHP, JS, XML, XML DOM, HTML DOM, DHTML, XPath, XQuery, XLink, XSL-FO, and currently XSLT) and I'm eager to return to my original goal, which is not to do more study, but to get on with applying my newfound knowledge to my new partially-built blogging website.I groaned when I got to the chapter titled "XSLT on the Server" (and the following chapter too) when the only code example shown there for beginning students to modify XML into XHTML was in ASP...but no PHP code alternative was offered (I was only invited to study the deprecated ASP in the tutorial...alas)! Since an ASP example was shown and there is an ASP tutorial, I assume there was something unique that needed to be shown to ASP users that wasn't already in the ASP tutorial, but since I have not studied ASP, I don't know what's unique about the ASP example shown here so that I could apply it to what was in the PHP tutorial (I'm just too new to be adept at this conversion). I note in your AJAX Tutorial that when you show ASP, you seem to always offer sort of a link to the PHP equivalent (kind'a, sort'a), but this does not seem true in the "XSLT on the Server" chapter", so...MY QUESTION: Do I really need to do an ASP tutorial because PHP cannot do the XML-to-XHTML conversion on the server (which is a great resolution to the browser incompatibility problem, by the way)! I assume the PHP equivalent was omitted for a logical reason, and was it that PHP can't do what ASP (either deprecated classic or the new net incarnation) can do in this particular context? Is PHP just not up to it?...and if it is, what would be an example of a PHP equivalent to the ASP given for ASP students (but for students who don't understand ASP)?PS: My cPanel for HostMonster shows Apache v2.2.11 (Unix), PHP v5.2.9, MySQL v5.0.75, and OS Linux. In the Database software available, MySQL, PostgreSQL and PHP administration software are offered. I see no reference to Windows or ASP anywhere on the cPanel info (and no ASP SQL administration software is listed either), so I'm puzzled whether studying ASP will actually help me implement my website with my provider (though maybe ASP is automatically included but just not listed on my cPanel...I'm just too new to this stuff to know yet). This is why I'm vitally interested in learning the PHP approach to the "browser incompatibility problem" to which you offered a brilliant solution in the "XSLT on the Server" chapter, except only ASP students were accommodated in this chapter it seems (but maybe the relevant example is somewhere else, but I don't know how to apply it to this particular solution because I'm still learning)! Please don't take this as a criticism; I just ache to know and the ache makes me needy (AND wordy)!

Link to comment
Share on other sites

If you have the link to that tutorial page we can probably get a conversion going. PHP and ASP can literally do anything the other can, they are both "complete" languages. It might take a lot of code, but it's possible.

Link to comment
Share on other sites

JustSomeGuy,Awesome! I'd love some help with the equivalent PHP code to the ASP code shown. I just don't know how to do it myself.The two w3schools tutorial pages (which are next to each other) which only show ASP but no PHP equivalent are:

  1. The Cross Browser Solution On The Server link at http://www.w3schools.com/xsl/xsl_server.asp, and
  2. The Edit, Submit & Update Tool (which is the following chapter) link at http://www.w3schools.com/xsl/xsl_editxml.asp

These two chapters above offer some very interesting and useful ideas for doing things "on the server". I'm excited!I'm also encouraged to hear that PHP is on par with ASP in that it can do anything the other can do (but if I understood your implication, it seems PHP may take more coding than ASP -- for some reason)! Anyway, I'm glad they both can accomplish the same outcomes and that a coder can use either one or the other.I'm sorry it may take a lot of code (as you say), but I don't know where to begin such a translation since I'm not multi-lingual in both coding structures. I sincerely appreciate your most kind offer and hope your efforts will be put into the two tutorials for other needy PHP-only students to study and follow as a model in order for these neat chapters to be accessible to everyone.

Link to comment
Share on other sites

but if I understood your implication, it seems PHP may take more coding than ASP
Not necessarily, one of them may require more code than the other, the only point I was making is that they can be considered functionally equivalent. PHP has a lot of built-in things, but if PHP doesn't have something built-in that ASP has, or vice-versa, it might take several lines of code to duplicate the functionality.Here's an article about using PHP to transform XSL:http://devzone.zend.com/article/1302For reference, here's the ASP code from the tutorial:
<%'Load XMLset xml = Server.CreateObject("Microsoft.XMLDOM")xml.async = falsexml.load(Server.MapPath("cdcatalog.xml"))'Load XSLset xsl = Server.CreateObject("Microsoft.XMLDOM")xsl.async = falsexsl.load(Server.MapPath("cdcatalog.xsl"))'Transform fileResponse.Write(xml.transformNode(xsl))%>

I would use this PHP code:

<?php // Allocate a new XSLT processor $xh = xslt_create(); // Process the document, returning the result into the $result variable $result = xslt_process($xh, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cdcatalog.xml', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cdcatalog.xsl'); if ($result) { 	echo $result;} else { 	echo "XML error: " . xslt_error($xh);  	echo "; Error code: " . xslt_errno($xh); } xslt_free($xh); ?>

Here's the ASP code for the second tutorial:

<%function loadFile(xmlfile,xslfile)Dim xmlDoc,xslDoc'Load XML fileset xmlDoc = Server.CreateObject("Microsoft.XMLDOM")xmlDoc.async = falsexmlDoc.load(xmlfile)'Load XSL fileset xslDoc = Server.CreateObject("Microsoft.XMLDOM")xslDoc.async = falsexslDoc.load(xslfile)'Transform fileResponse.Write(xmlDoc.transformNode(xslDoc))end functionfunction updateFile(xmlfile)Dim xmlDoc,rootEl,fDim i'Load XML fileset xmlDoc = Server.CreateObject("Microsoft.XMLDOM")xmlDoc.async = falsexmlDoc.load(xmlfile)'Set the rootEl variable equal to the root elementSet rootEl = xmlDoc.documentElement'Loop through the form collectionfor i = 1 To Request.Form.Count  'Eliminate button elements in the form  if instr(1,Request.Form.Key(i),"btn_")=0 then	'The selectSingleNode method queries the XML file for a single node	'that matches a query. This query requests the value element that is	'the child of a field element that has an id attribute which matches	'the current key value in the Form Collection. When there is a match -	'set the text property equal to the value of the current field in the	'Form Collection.	set f = rootEl.selectSingleNode("field[@id='" & _	Request.Form.Key(i) & "']/value")	f.Text = Request.Form(i)  end ifnext'Save the modified XML filexmlDoc.save xmlfile'Release all object referencesset xmlDoc=nothingset rootEl=nothingset f=nothing'Load the modified XML file with a style sheet that'allows the client to see the edited informationloadFile xmlfile,server.MapPath("tool_updated.xsl")end function'If the form has been submitted update the'XML file and display result - if not,'transform the XML file for editingif Request.Form("btn_sub")="" then  loadFile server.MapPath("tool.xml"),server.MapPath("tool.xsl")else  updateFile server.MapPath("tool.xml")end if%>

I can get this started, but we may need boen_robot or someone with more XML experience than I have to finish it off. I guess I'll try it using the simpleXML extension.

<?php function loadFile($xmlfile, $xslfile){  $xh = xslt_create();   $result = xslt_process($xh, $xmlfile, $xslfile);   if ($result) { 	echo $result;  }   else { 	echo "XML error: " . xslt_error($xh);	echo "; Error code: " . xslt_errno($xh);   }   xslt_free($xh); }function updateFile($xmlfile){  $xml = simplexml_load_file($xmlfile) or exit('Error loading ' . $xmlfile);    foreach ($_POST as $k => $v)  {	if (strpos($k, 'btn_') === false)	{  	  $nodes = $xml->xpath("field[@id='" . $k . "']/value");	  foreach ($nodes as $i => $node)	  {		$node->Text = $v;		$nodes[$i] = $node;	  }	  // need to write the changed nodes back to the XML structure	}  }  // need to write the XML structure back to the file}#If the form has been submitted update the#XML file and display result - if not,#transform the XML file for editingif (isset($_POST['btn_sub']) && $_POST['btn_sub'] == ''){  loadFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tool.xml', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tool.xsl');}elseif (isset($_POST['btn_sub']) && $_POST['btn_sub'] != ''){  updateFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tool.xml');}?>

I'm not entirely sure if simplexml is the right extension to use for this, or if I'm doing the xpath correctly. I'm also not sure how to write a structure like a simplexml structure back to the file, I'm sure there's an automated way other than looping through all the nodes and writing it all manually. That should be a start though, hopefully we can get some more feedback.

Link to comment
Share on other sites

JustSomeGuy,Thanks for the link to the "Using PHP and XSL to Transform XML Into Web Content" article.I've looked at the translations you've done and I am so appreciative of your labor.Since you feel we need more feedback on the second one, I look forward to seeing what others have to offer too. I would never have been able to pull off these translations myself, and though I tried to look at the original ASP and compare it to your PHP translation, I stopped doing this since I was getting massively confused, and decided to stick with your PHP translation only since that is what I studied (I just don't have the resource background to follow the ASP models at a step-by-step level). Since the model for the second tutorial is not quite complete or up to your expectations yet, I have not studied it as well as your first translation (about which you feel more comfortable).QUESTION: Do I understand you correctly that in your translation...

  • "dirname(__FILE__)" is equivalent to the ASP model's original "Server" reference?, and
  • "DIRECTORY_SEPARATOR" is equivalent to the ASP model's original "MapPath" reference?

Since you used these different references, I wanted to confirm if this was something unique required by PHP for this particular application, or if this was just your making it generic and applicable to other instances.Again, I hope this labor of yours (and others who may join in too) gets into the actual tutorial from which these were taken so other PHP students can learn from them while studying the chapters involved. Hopefully, in time, there will always be a PHP equivalent when ASP is shown, and not only one (and if there is only one, it does seem to always be ASP alone, suggesting a preference towards ASP by w3schools -- but maybe I'm mistaken here, and I don't mean this as a criticism as much as it seems to indicate a preferencial bias). The majority of tutorials do have both ASP alongside PHP, but not all of them yet (again, maybe I'm overly sensitive about this and not objective).I do SO want to stop studying and get on with applying my newfound knowledge to the blogging website that I'm building, since actually applying knowledge is what makes it real and solid in the memory, but I know I'll be back to the tutorials again and again as I need to refresh and reinforce what I've learned. W3schools is great! ...and JustSomeGuy, thanks again!

Link to comment
Share on other sites

In ASP, if you use Server.MapPath it will return the current working directory. If the ASP script you're running on the server is at c:\inetpub\wwwroot\asp_stuff\script.asp, and inside the script you have Server.MapPath("log.txt"), it will return "c:\inetpub\wwwroot\asp_stuff\log.txt", so it will map a filename to a file in the current working directory of the script that's executing.In PHP, the __FILE__ constant will always hold the filename of the script that it's in, or the current running script. It holds the full path and filename. The dirname function returns the directory part of any path, without the ending slash, so if you pass the __FILE__ constant to the dirname function, it returns the full directory name that the current PHP script is in. Since it doesn't include the ending slash, the DIRECTORY_SEPARATOR constant holds whatever slash is appropriate for the operating system that PHP is running on. The rest of the line adds the filename.So this in PHP:dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cdcatalog.xml'evaluates to the same thing as this in ASP:Server.MapPath("cdcatalog.xml")The two sets of code don't necessarily have a line-by-line equivalence, they're just [supposedly] functionally equivalent.

Link to comment
Share on other sites

JustSomeGuy,I'm glad I asked about dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cdcatalog.xml' since I didn't know these things (and if it was in the tutorial, it just went by me swoosh!...since I've not been applying my knowledge to real-world applications yet and it won't stick until I do). I've got to review and knuckle down applying this information! Thanks for being so patient to explain and example all this stuff!QUESTION: I note your consistent use of spaces on both sides of the dots in dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cdcatalog.xml' and are those spaces needed or is it just irrelevant (it's OK if you do and it's OK if you don't). It's your consistency that makes me ask.By the way, I'm glad you mentioned your PHP equivalents are not a transliteration (a line-by-line translation) of the ASP code, since it was making me dizzy to try to understand it that way. It's more important that they are functionally equivalent.I look forward to someone else joining you on helping with a full PHP equivalent to the lonely ASP code found in the tutorial at http://www.w3schools.com/xsl/xsl_editxml.asp, since you indicated you did not yet feel fully comfortable with your first functional PHP translation attempt, as this particular passage seems quite useful and it would be excellent to have a solid example to model in real applications. I also hope someone can come up with "an automated way other than looping through all the nodes and writing it all manually" (as you suggested in your post), as that would be quite educational to see!

Link to comment
Share on other sites

Whitespace generally isn't necessary in PHP code, I just think it's easier to read and try to be consistent. I think it's quicker to understand this:

if (isset($_POST['btn_sub']) && $_POST['btn_sub'] == ''){  loadFile(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tool.xml', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tool.xsl');}

than this:

if(isset($_POST['btn_sub'])&&$_POST['btn_sub']==''){  loadFile(dirname(__FILE__).DIRECTORY_SEPARATOR.'tool.xml',dirname(__FILE__).DIRECTORY_SEPARATOR.'tool.xsl');}

Link to comment
Share on other sites

JustSomeGuy,Since we've had no one join us here in this thread, I'm going to the PHP group with a new topic to see if I can drum up some help with the second ASP code that you said you were less sure about. I'm not sure our current topic "Asp or Php" is clear enough to draw wider attention to what we're talking about here in your and my discussions, so I'm going to use the topic heading "Help...PHP Code Missing In Tutorial" in the PHP group to see if it draws wider attention. The topic in the current thread sounds like it's a discussion about the merits of ASP vs PHP, and that's not what you and I have been interacting about; we've been interacting about a translation instead.Thanks for the PHP code for the first ASP code set we talked about here, and I will keep a copy of it and also what you developed on the second set. If someone comes up with a more full or certain solution to the second set in the new thread I'm starting, I do hope you will look at it and give it your stamp of approval or comment one way or another about its strengths or weaknesses. I value your opinion. Thanks!PS: I'm not bringing up the first tutorial we interacted about, since you seemed confident in the solution you offered. I'm only bringing up the second longer ASP code for wider input and/or PHP translation.

Link to comment
Share on other sites

Ewwww.... what an U G L Y topic.It starts out as "ASP or PHP", goes on to "What's the difference" (even though it was mentioned...), and turns into... I have no idea what, but certainly something that doesn't belong in here or any forum...I have to say that I agree on one mentioned point though... the W3Schools tutorial doesn't feature sample code of using XSLT on the server with PHP. The reason I think is because the XSLT tutorial was written in PHP4 days, and probably before the PHP tutorial had a make over (and certainly - before the birth of this forum) and it hasn't been updated since.Anyway, in those bad old days, you'd use the XSLT extension, which is the one justsomeguy demonstrates. Today, in PHP5, you'd use the XSL extension, which to the untrained eye may seem confusing. If you bother enough to read the PHP manual on the XSLT extension, you'll find the XSL extension though, and if you look a little at the XSL extension documentation, you'll also find some interesting working examples.In case it wasn't clearly outlined before: Whatever you can do in ASP, you can do in PHP as well, and vice-versa. There may be different ways to do it, but there's always a way.

Can we use ASP on a .php page? Just wondering?
No... Which brings me to another point that was mentioned, and I hope it doesn't get asked directly or indirectly again - ASP(.NET) is not exactly a language itself. It's more of a runtime/framework in which other languages run. It can use VBScript, JScript, C# or other .NET aware languages. The examples in W3Schools most often use VBScript.Having said that, it may be possible to go the other way around - use PHP in ASP. Or rather, use PHP as ASP.NET's language (instead of the above mentioned languages). I believe it was justsomeguy that once showed a list of .NET compatible languages (maybe not exactly that list, but a similar one for sure). You can see there's a PHP implementation (a separate one though!) for .NET.
Link to comment
Share on other sites

Boen_Robot, thanks for showing up! In your post, you said about this thread:

It starts out as "ASP or PHP", goes on to ... something that doesn't belong in here or any forum...I have to say that I agree on one mentioned point though... the W3Schools tutorial doesn't feature sample code of using XSLT on the server with PHP.
Since JustSomeGuy said on May 18 2009, 09:07 AM about the missing code you mentioned above and about his attempt to translate it:
I can get this started, but we may need boen_robot or someone with more XML experience than I have to finish it off. I guess I'll try it using the simpleXML extension. ... I'm not entirely sure if simplexml is the right extension to use for this, or if I'm doing the xpath correctly. I'm also not sure how to write a structure like a simplexml structure back to the file, I'm sure there's an automated way other than looping through all the nodes and writing it all manually. That should be a start though, hopefully we can get some more feedback.
I was hoping you'd comment on what JustSomeGuy said, especially since you were mentioned specifically by name.JustSomeGuy did his best, but he left some things open:
  • simpleXML, he said, he was not sure was the right extension for this file (and I looked all throughout the tutorials and didn't find any reference at all to "simpleXML extensions", so I'm really stumped here about this newly-identified extension, and looked forward to your clarification or alternative coding example -- unless it's the XSLT extension vs the XSL extension, which you suggested in your email, which kind of goes over my head since the word "simple" doesn't appear in these references, and it also doesn't speak to how to do what JustSomeGuy was attempting to show in real code examples, which would be preferred to saying "Go study some more documentation" and read more and more, which will certainly be good in time, but which will not solve the current coding that is being addressed).
  • Doing Xpath correctly was something that JustSomeGuy was not sure about (and I hoped you'd clarify or example too if you knew).
  • Writing a structure like simpleXML back to a file was something JustSomeGuy was uncertain about (and I hoped you'd weigh in on this topic with example coding if you were aware of how to do it or what an alternative might be).
  • Finally, "an automated way other than looping through all the nodes" as indicated by JustSomeGuy sounded quite interesting (and I hoped you'd respond with code if you knew a way, as that'd be quite educational!).

However, you did not seem to speak to these coding issues with examples in your recent post (though you spoke generally and editorially about this thread), and I was hoping for more concrete coding feedback, just like JustSomeGuy said. We're just trying to finish off a coding example that the tutorial lacks and I think this example could be useful for other PHP students too!PS: I did indeed notice all the different links you provided in the individual words in your previous post and I will follow up on them in time, but in the short run, it'd be nice to have some code that could be suggested to w3schools that could just be inserted into the tutorial as the missing PHP equivalent to the ASP which is already shown (PHP students need this "in the tutorial", not only in the forum, as in the forum it will be harder and harder to find in time). If a reasonable, ready-to-go code is presented to the right folks, I'm sure it'll get in sooner into the right tutorial chapter than if it just goes onto a Post-It as something to write or figure out someday. JustSomeGuy has confidence in you, and that makes me respect you, and won't you please consider helping with the particular code example which needs your seeming magic (as implied by JustSomeGuy)!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...