ted_chou12 Posted December 25, 2006 Share Posted December 25, 2006 [code]<?phpif ($message != "" && $title != ""){$file = fopen("newscomments/comments[$number].txt","w+");fwrite($file,"$title;seDp#$datetime;seDp#$message\r\n");foreach ($txtfile as $txtfile) {fwrite( $file, "$txtfile");}fclose($file);$title = "";$message = "";header("location: include.php?page=newsconfirm");}?>[/code]this is how I used it, but after writing the page doesnt redirect to the confirm page at all, it simply stays on the writing page, (it does write to the text file.Can anyone have a look at this?Thanks Ted. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted December 25, 2006 Share Posted December 25, 2006 [code]<?phpif ($message != "" && $title != "") // do you need to do isset() on $message and $title as well? {$file = fopen("newscomments/comments[$number].txt","w+"); //where is $number declared? fwrite($file,"$title;seDp#$datetime;seDp#$message\r\n"); //where is $datetime declared? foreach ($txtfile as $txtfile) // What I don't think this is needed...? {fwrite( $file, "$txtfile");} // ditto fclose($file); $title = ""; $message = ""; header("location: ./include.php?page=newsconfirm");}?>[/code]I can't figure what you are trying to do here... Quote Link to comment Share on other sites More sharing options...
mendoz Posted December 25, 2006 Share Posted December 25, 2006 Does it give you "headers already sent"? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 25, 2006 Author Share Posted December 25, 2006 nope Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 25, 2006 Author Share Posted December 25, 2006 what I am trying to do is to redirect the visitor after they made an entry,(write into the text file), but the redirection doesnt seem to work, by the way, the redirection page is "newsconfirm.php?..." one.ThanksTed Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 25, 2006 Author Share Posted December 25, 2006 this is the first part to it:[code]<?phpif(isset($_POST['submit'])){$number = $data[$news][2];$txtfile = file("newscomments/comments[$number].txt");$title = $_POST['title'];$message = $_POST['message'];$datetime = date("M d, Y");?>I didnt put it in previously because I though it isnt that important...[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 $username = $_SESSION['sconlineusername'];require("../mysqlconnection.php");$sql = "SELECT * FROM usercus WHERE username = '$username'";$result = mysql_query($sql);if (mysql_num_rows($result) == 0){header("location: editprofile.php");}this one doesnt work as well any other command works but head location doesntlike i tried echo, print they all work, but not redirection...why is that?is there a bug? Quote Link to comment Share on other sites More sharing options...
trq Posted December 26, 2006 Share Posted December 26, 2006 It needs to be a capital 'L' in location.[code=php:0]header("Location: editprofile.php");[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 nope, that didn't made any difference.. Quote Link to comment Share on other sites More sharing options...
trq Posted December 26, 2006 Share Posted December 26, 2006 Have you got ANY output being sent to the browser first? This includes ANY whitespace.A read of [url=http://www.phpfreaks.com/forums/index.php/topic,37442.0.html]this[/url] sticky might help explain why its not working. Quote Link to comment Share on other sites More sharing options...
monkey_05_06 Posted December 26, 2006 Share Posted December 26, 2006 header requires a full path be sent. Or at least it's supposed to. So:[code]if (isset($_SERVER["HTTP_HOST"])) $host = $_SERVER["HTTP_HOST"];else $host = $_SERVER["SERVER_NAME"];$uri = dirname($_SERVER["PHP_SELF"]);if ($uri === "\\") $uri = "/";if ($uri[strlen($uri) - 1] !== "/") $uri .= "/";header("Location: http://" . $host . $uri . "include.php?page=newsconfirm");[/code]Also, AFAIK the header function is case-insensitive in regards to the HTTP header choice (i.e., "Location" === "location"). But I could be wrong about this, so it's probably safest just to use "Location". Quote Link to comment Share on other sites More sharing options...
trq Posted December 26, 2006 Share Posted December 26, 2006 Ah... checking the http now I find that....[quote]Field names are case-insensitive[/quote]well I'll be.... Ive allways thought they where case sensitive. Learn something everyday. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 nope that doesnt work either, okay, i read the sticky, but i still dont quite understand what they are talking about, actually, i do have login session and cookies, the page looks something like this:[code]<?php include("login.php");require("../mysqlconnection.php");$sql = "SELECT * FROM usercus WHERE username = '$username'";$result = mysql_query($sql);if (mysql_num_rows($result) == 0){header("Location: http://sconline.66ghz.com/users/editprofile.php");}?>[/code]before and after are just html codes, not relatedand login.php contains cookies and sessions...the above header location is the one which I am talking about...yeap thorpe, so i prefer all lower cases, easier to readThanksTEd Quote Link to comment Share on other sites More sharing options...
trq Posted December 26, 2006 Share Posted December 26, 2006 [quote]before and after are just html codes, not related[/quote]Read the thread again. You cannot have ANY output sent to the browser (including any html) before calling the header() function. Turn error reporting on and you will see a 'headers allready sent error'.Re organize your code so that there is no html outputted before your call to header(). Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 <?php $command = header("location: editprofile.php");?>html code<?php include("login.php");require("../mysqlconnection.php");$sql = "SELECT * FROM usercus WHERE username = '$username'";$result = mysql_query($sql);if (mysql_num_rows($result) == 0){$command;}?>should this work them? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 26, 2006 Author Share Posted December 26, 2006 yeah, it kind of worked... cheers....but now i am stuck on the editprofile.php page nomatter if i logged in or what...thats no good, the user should only be able to access this page if they are logged in.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.