Page 1 of 1

header() problem - redirecting from an included script

Posted: Tue Jan 04, 2011 7:33 pm
by mecha_godzilla
Hi,

I'm trying to extend a site based around a very simple bespoke CMS that my friend has had set up for them. The way the site works is that there is just one main script (index.php) which loads content into different parts of a template depending on what the URL looks like, with all the content being retrieved from a database.

What I now need to do is add a bookings system to it that lets people reserve spaces on different types of events and how I've done this is by writing a new script (bookings.php) that gets included in the main script using require_once() if a specific URL is called.

I've now written the script and it all works correctly but I'm having a real problem redirecting the visitor to another page when the booking has been received (a PayPal payment page in fact) because the header() redirection has to be called from within the bookings script (bookings.php) but by this point the main script (index.php) has already started echo-ing out the page template.

Can anyone offer any suggestions as to how I could get the redirection working?

Thanks,

Mecha Godzilla

Re: header() problem - redirecting from an included script

Posted: Tue Jan 04, 2011 11:57 pm
by thecodewall
try using javascript I think this may help.

<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>

Re: header() problem - redirecting from an included script

Posted: Wed Jan 05, 2011 4:22 pm
by mecha_godzilla
Thanks for that - I hadn't considered using JavaScript to be honest :)

What I might try and do is add a check at the very top of the index.php script to see if the bookings form has been submitted and do the redirection from there - not particularly elegant but it would allow me to 'submit' the PayPal details (bearing in mind that the PayPal button is really a form and not just a button that you click on).

Thanks again!

M_G