简体   繁体   中英

Redirect to XML file and back to PHP page possible?

I'm currently coding an ID filter, whenever a user submits an ID it will pick out all the orders and filters out all the ID's you DON'T want to see from the XML file.

a little preview - XML

<filter><!-- Copy filter-item and put the order-id in as the value to skip it-->
    <filter_item>1138850639</filter_item><filter_item>1138371172</filter_item><filter_item>1137835945</filter_item></filter>
</root>

PHP

if (isset($_POST['load'])) 
{
    

    $orderFilter = $_POST['orderItemFilter'];
    
    $xml = simplexml_load_file("Config.xml");
    $sxe = new SimpleXMLElement($xml->asXML());
    $itemsNode = $sxe->filter;
    $itemsNode->addChild("filter_item", $orderFilter);
    $sxe->asXML("Config.xml");  
}   

Now the problem is that the file itself does contain the ID, but the Config.xml HAS TO BE RUNNED to be able to display the final order page. Is there a way to redirect from an XML file to return to the previous page?

There are two mentioned to do this.

First you can do this in Javascript.

 javascript:history.go(-1)

Second, you can do this in PHP, remember it is not ggood idea to because it will not work on HTTPS and headers can be hijacked and reirect to unwanted pages.

header('Location: ' . $_SERVER['HTTP_REFERER']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM