Swithching to a new file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

sam
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jun 22, 2002 6:43 am
Location: South Africa
Contact:

Swithching to a new file

Postby sam » Fri Dec 06, 2002 2:05 am

Hi there

How do I transfer control from within a certain php file to another file. For instance say I am executing code in A.php and I have done all the execution that I want and now want to goto B.php and pass is some variables.

I have been using code like:
header("Cache-Control: no-cache, must-revalidate");
header("Location:./freecards.php?errMsg=$errMsg");


But is there not a better ay of doing this ?

Thanks
Sam[/quote]

Dmitrit Plakhotnik
New php-forum User
New php-forum User
Posts: 13
Joined: Fri Nov 01, 2002 6:56 am

Postby Dmitrit Plakhotnik » Fri Dec 06, 2002 3:27 am

if you want use for redirect header("Location:"), make sure what before nothing outputing on the page.

for example
wrong code

Code: Select all

 <? echo "test";
header("Location: index.php"); ?>


right code

Code: Select all

 <? header("Location: index.php"); ?>



but of you must redirect after printing use jabascript

Code: Select all

function pggo($prfx,$me="document.location"){
  echo "
    <script language=javascript>
  ";
  if($me=="document.location") echo "nm=new String($me);";else echo "nm=new String('$me');";
   echo "   if(nm.length<100)document.location=nm+'$prfx';
    </script>
  ";
};

sam
New php-forum User
New php-forum User
Posts: 4
Joined: Sat Jun 22, 2002 6:43 am
Location: South Africa
Contact:

Postby sam » Sat Dec 07, 2002 12:50 am

Thanks for that:

Yesturday I spent about three hours working out that I had white spaces after my ?> closing tags on files that I was including before redirecting :twisted:

Panfull stuff, we get ourselves into with those invisible white spaces :wink: .

Another question though, my server does not explicitely tell me that output was passed before the header location was executed. How do I change this. Is it an apache setting or php setting ?

Thanks again though
Sam

wiredme
New php-forum User
New php-forum User
Posts: 7
Joined: Sun Dec 08, 2002 9:02 pm

Postby wiredme » Sun Dec 08, 2002 9:49 pm

sam wrote:Thanks for that:

Yesturday I spent about three hours working out that I had white spaces after my ?> closing tags on files that I was including before redirecting :twisted:

Panfull stuff, we get ourselves into with those invisible white spaces :wink: .

Another question though, my server does not explicitely tell me that output was passed before the header location was executed. How do I change this. Is it an apache setting or php setting ?

Thanks again though
Sam



try to configure you register_globals it might be off in you php.ini


Return to “PHP coding => General”

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron