Jump to content

Archived

This topic is now archived and is closed to further replies.

timgetback

how to redirect with php.

Recommended Posts

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

Share this post


Link to post
Share on other sites
note on using
<META HTTP-EQUIV=Refresh CONTENT=\"10;url=rederict.php\">
This does not seem to work on IE

Share this post


Link to post
Share on other sites
Change this:

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

$result = mysql_query($sql,$connection) or die (mysql_error());
[/code]

to

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

$result = mysql_query($sql,$connection) or die (mysql_error());
[/code]

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

[code]
$result = mysql_query($sql,$connection) or die (mysql_error());
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
when i typed the code you gave me:

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

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.

Share this post


Link to post
Share on other sites
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
?>

Share this post


Link to post
Share on other sites
or just
[code=php:0]echo '<script type="text/javascript>
window.location = "http://www.example.com/page.php
</script>';[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[quote author=SharkBait link=topic=102866.msg408914#msg408914 date=1154617365]
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.


[/quote]

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?

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
i was just wondering can i send an html link with php mail:

[code]$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");
?>[/code]

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

Share this post


Link to post
Share on other sites
[code]$message= "The information is that blah blah blah blah <a href='http://www.somesit.com'>Here</a> to see wat im talkin about.";[/code]

Share this post


Link to post
Share on other sites
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.....

Share this post


Link to post
Share on other sites
[quote author=timgetback link=topic=102866.msg410288#msg410288 date=1154799359]
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.....
[/quote]

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

[code]header("Location: thank_you.php");[/code]

Share this post


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

Share this post


Link to post
Share on other sites
You need to be more careful with ' and "

Maybe this'll work:

[code]echo "<script type='text/javascript'>window.location=http://www.somesite.com</script>";[/code]

Share this post


Link to post
Share on other sites
I would to say thank you all for all your help... My Project was a complete success.... and all you guys KICK ASS!!!!!!! cause i had no chance in hell of completeing my project in the one week that i did it in... And i hope all my dumbass questions will help other noObs....

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.