PHP check for valid parameter passed through the URL in XSLT

ViXan

New Member
I have the following XML that stores 2 movie ID's and their titles\[code\]<moviesxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="test.xsd"><movie movieID="1"> <title>Movie 1</title></movie><movie movieID="2"> <title>Movie 2</title></movie></movies>\[/code\]My XSL displays movie titles as hyperlinks that take the user to movie_details page to display movie information based on the ID that was passed through the URL.movies_list.xsl\[code\]<xsl:template match="/"> <xsl:text>Movies list</xsl:text> <xsl:apply-templates select="/movies/movie"/></xsl:template><xsl:template match="movie"> <xsl:element name="a"> <xsl:attribute name="href">movie_details.php?movieID=<xsl:value-of select="@movieID"/></xsl:attribute> <xsl:value-of select="title"/> </xsl:element> <xsl:element name="br" /></xsl:template>\[/code\]This is my movie_details.php file\[code\]<?php$xml = new DOMDocument();$xml->load('test.xml');$xsl = new DOMDocument;$xsl->load('movie_details.xsl');$proc = new XSLTProcessor();$proc->importStyleSheet($xsl);$params = $_GET['movieID'];$proc->setParameter('', 'movieID', $params);echo $proc->transformToXML($xml);?>\[/code\]I would like to do the following parameter validation in movie_details.php1) Check that movieID passed through the URL is valid and exists in the XML file. If I manually change the URL in my browser to \[code\]myserveraddress.com/movie_details.php?movieID=3\[/code\], I get a blank page because movieID=3 does not exist in the XML file and there is nothing to display.If movieID is invalid and does not exist in the xml, then I would like the page to redirect me to index.php2) Check that movieID parameter is passed through the URL at all. For example if I manually change the URL in my browser to \[code\]myserveraddress.com/movie_details.php\[/code\], the page should redirect me to index.php as there are no parameters passed in the URL.
 
Back
Top