Jump to content


Predifined Function-- [PHP]


2 replies to this topic

#1 liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 20 November 2005 - 08:58 AM

Hello, Well I am making a script in php and I added
 function redirect($url)
  { 
   header ("location: $url");
   exit;
  }
Ok, well works great, except if it gets called 2 times, on the same page...then errors take over...so How do I make it so it determines wether or not the function exists?

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 20 November 2005 - 12:05 PM

I believe you asked your question wrong. The last 2 words of your question could be the answer: http://php.net/manua...tion-exists.php

But since i assume you want to know whether or not the function has been called. You could try a static variable (i haven't done much work with these, but you could give it a try.
function redirect($url){
   static $called=0;
   if(empty($called){
	  header ("location: $url");
	  $called = 1;
   }
}
But i doubt that's your problem. Headers, unlike php/html, tend to be case-sensitive (mostly for cross-browser compatiblity). http://php.net/manua...tion.header.php

So what you'd want to use is this:
function redirect($url){
   header ("Location: $url");
}
exit() is not needed since that should redirect you the second it's called.

Edited by rc69, 20 November 2005 - 12:13 PM.


#3 Programmerguy150

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Interests:Eating your soul<br />P2L<br />PHP<br />Tutorials<br />Eating your soul..

Posted 21 November 2005 - 09:42 PM

Sorry, disremind this:/

Edited by Programmerguy150, 21 November 2005 - 09:42 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users