gwledig Posted April 21, 2009 Share Posted April 21, 2009 Hi I have a basic script running which will be called from a hyperlink on a Web page, this fires up the PHP script in the browser window and performs the stuff I want it to do (saves a file from the web to a local location), when the script has run I'm left with a blank screen. I'd like to then redirect the page to a Website, but I've tried using the header declaration and this does redirect BUT the script doesnt run ! Does anyone know of a way to send the client/user to a URL after a function or procedure has run? thanks gwledig Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 21, 2009 Share Posted April 21, 2009 <?php ... header("Location: http://www.somesite.com/somepage.php"); die(); ?> Do your script before the header...it will run. Or post the complete script here it may help us find the error. Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/#findComment-815423 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2009 Share Posted April 21, 2009 There can't be any HTML output before the header though, if there is use meta refresh to redirect or rethink your code logic. Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/#findComment-815442 Share on other sites More sharing options...
Mchl Posted April 21, 2009 Share Posted April 21, 2009 There can't be any HTML output before the header though There can be NO output whatsoever before. Not even 0x00. Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/#findComment-815448 Share on other sites More sharing options...
gwledig Posted April 21, 2009 Author Share Posted April 21, 2009 Hi, its basicly saving a web-published xml page as a local xml file (sharepoint uses horrible long urls without a proper .xml extension), so saving the sharepoint RSS file as .xml allows me to work with it online. This script is just a php file which needs to run when the user has added news to a news feed in sharepoint, so I;ll provide them with a 'Publish' button which runs the php script to create the new RSS xml file. Unfortuantely when the user runs the php script it opens the php page and ends up just sitting there after its done its stuff building the xml file. I suppose I could add a link 'Return to Intranet' or something but thats kinda messy... Ideally I want the script to run then direct back to a url of my choosing... thanks again folks... --------------------- <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://vocal-external.liv.ac.uk/sites/catherallp-test/news/_layouts/listfeed.aspx?List={C1F668FA-F047-427F-93B0-8344EA008518}'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $remoteFileContents = curl_exec($ch); $localFilePath = "C:\Mowes\www"; $localFileName = "ok.xml"; $newFileHandle = fopen($localFilePath."/".$localFileName, "w"); fwrite($newFileHandle, $remoteFileContents); fclose($newFileHandle); echo '<h1 style="font-face: arial; color: #0033CC;"><strong>Publishing News Page, Please Wait....</strong></h1>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/#findComment-815461 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2009 Share Posted April 21, 2009 meta refresh would be best here then Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/#findComment-815471 Share on other sites More sharing options...
gwledig Posted April 21, 2009 Author Share Posted April 21, 2009 this worked, it processed the file then redirected me.. I also tried basic echo meta refresh but it didnt process the script.. thanks a ton folks gwledig header("Location: http://www.somesite.com/somepage.php"); die(); Quote Link to comment https://forums.phpfreaks.com/topic/155035-redirecting-to-a-url-in-php/#findComment-815475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.