Jump to content


Photo

how to redirect with php.


  • Please log in to reply
41 replies to this topic

#21 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 August 2006 - 06:05 PM

You can place header, sessiojn_start, mail, setcookie or any other function that changes the headers anywhere within your script, aslong as there is no output before the use of these functions.


mail? :)

Yes believe it or not mail does send headers.

if you have header somewhere other than the top
you need ob_start(); at the top of the page

You'll want to add ob_start(); at the top of each PHP page and ob_end_flush(); at the end of each PHP page.

#22 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 03 August 2006 - 06:07 PM

But I'm using mail in a place where cookie/session and all that stuff would not work. But this wonderful piece of letters works :) And the mail even gets delivered  8)
I'm just a guy who likes to code for fun...

#23 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 August 2006 - 06:10 PM

I'm not sure with that one then, however I remember reading something about mail and headers in an online article.

#24 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 03 August 2006 - 06:11 PM

Well yeah, there is headers that is sent with the mail, but they are not really the same thing...
I'm just a guy who likes to code for fun...

#25 Dobakat

Dobakat
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 03 August 2006 - 06:21 PM

echo "

<SCRIPT LANGUAGE='JavaScript'>

window.location='rederict.php';



</script>

";

thats what i use or you can use..

print "<META HTTP-EQUIV=Refresh CONTENT=\"10;url=rederict.php\">";

#26 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 03 August 2006 - 11:31 PM

so would i add that java script to my php file??? cause when i added
include 'redirect.php';
at the end it didnt redirect the url......

#27 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 11:52 PM

note on using
<META HTTP-EQUIV=Refresh CONTENT=\"10;url=rederict.php\">
This does not seem to work on IE
Tell me the problem, I will try tell you the solution

#28 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 04 August 2006 - 02:49 AM

Change this:

$sql = mysql_query("INSERT INTO users (username, password) 
        VALUES('$username', '$passwd')") or die (mysql_error());

$result = mysql_query($sql,$connection) or die (mysql_error()); 

to

$sql = "INSERT INTO users (username, password) 
        VALUES('$username', '$passwd')";

$result = mysql_query($sql,$connection) or die (mysql_error()); 

your using the result of the query instead of the query itself or you could just remove this line altogether if you prefer

$result = mysql_query($sql,$connection) or die (mysql_error());

:: gucci.com ::
:: blockbuster.com ::

--------------------

#29 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 04 August 2006 - 04:39 AM

I prefer meta refreshes over PHP header redirects...  I just like meta tags because they can be put anywhere though... i also use

<script type="text/javascript>
window.location = "http://somesite.com/page.php";
</script>

a lot.
Why doesn't anyone ever say hi, hey, or whad up world?

#30 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 04 August 2006 - 07:10 AM

when i typed the code you gave me:

<script type="text/javascript>
window.location = "http://somesite.com/page.php";
</script>

It kept giving me this error:

"Parse error: syntax error, unexpected '<' in /home/someplace/public_html/register3.php on line 31"
line 31 happens to be the place where the above code started.


#31 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 10:15 AM

well parse error is php
You forgot to close the php
<?
//your php code
?>
<script type="text/javascript>
window.location = "http://www.example.com/page.php
</script>
<?
//Continue php
?>
Tell me the problem, I will try tell you the solution

#32 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 04 August 2006 - 12:40 PM

or just
echo '<script type="text/javascript>
window.location = "http://www.example.com/page.php
</script>';

I'm just a guy who likes to code for fun...

#33 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 04 August 2006 - 02:58 PM

For some unexpected reason... neither the exho'script..........</script>'; works or even closing php... ?> and reopening works. Nothings seems to be redirecting my code... and i wanted to redirect after i was done with the output

#34 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 August 2006 - 06:51 AM

Depends on what else you want to do..

Just remember that you cannot send any output to the browser prior to the header() and anything after won't be seen because its not on that page anymore.

As for it continuing execution of the script after the header() function, I am not sure if it does any of it.  I usually have exit() after my header() and then whatever else I need to do will be in the script that you're calling header with.



Ive gotten alot of conflicting messages.... like if i put ob_start(); and ob_flush(); in my code i can put the header() fuction anywhere.... unfortunately i tried n it didnt  work but it could be the way i did it.  i also tried
echo ' script type="text/javascript>
window.location = "http://somesit.com/index.php";
</script>';

but that didnt work... it didnt cause any errors but it didnt work.. so wats up?

#35 xec

xec
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 05 August 2006 - 07:14 AM

header("location: http://www.domain.com");
    exit;

------------------------
few mistake you need to correct in order to redirect your page...

header("Location: http://www.domain.com");
exit;



#36 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 August 2006 - 05:06 PM

i was just wondering can i send an html link with php mail:

$message= "The information is that blah blah blah blah echo "<a href=http://www.somesit.com">Here</a> to see wat im talkin about.";
mail("email@domain","Account INfo",$message,"from: forcsee.site"); 
?>

cause it gave me this error: Parse error: syntax error, unexpected '<' in /home/getsam2/public_html/register3.php on line 30


#37 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 August 2006 - 05:32 PM

$message= "The information is that blah blah blah blah <a href='http://www.somesit.com'>Here</a> to see wat im talkin about.";

Legend has it that reading the manual never killed anyone.
My site

#38 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 August 2006 - 05:35 PM

thanks.... but i was still hoping to figure out how i can redirect using header() or some other function at the end of my php script.....

#39 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 August 2006 - 05:51 PM

thanks.... but i was still hoping to figure out how i can redirect using header() or some other function at the end of my php script.....


You can only use header() if the script has not output ANYTHING to the browser. Example:

header("Location: thank_you.php");

Legend has it that reading the manual never killed anyone.
My site

#40 timgetback

timgetback
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 05 August 2006 - 05:57 PM

ok... cause i tried to include 'redirect.php'; at the end of my script it didnt wok.... so when i used
echo "<SCRIPT language= javascript>window.location="http://www.somesite.com</script>';
I keep getting this messgae: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/getsam2/public_html/register3.php on line 36





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users