calmchess Posted July 1, 2007 Share Posted July 1, 2007 Hi I have a php script with an If statment that fires if a user successfully logs in which then prints a success message...but instead of a success message i want the user to be automatically redirected to a diffrent html page....I tried to use header but as you can guess I get a header has already been sent error so how should i write the code so that i can redirect the page if successful login? Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/ Share on other sites More sharing options...
trq Posted July 1, 2007 Share Posted July 1, 2007 so how should i write the code so that i can redirect the page if successful login? Without seeing your code, all we can do is give examples.... The logic is simple. <?php if (isset($_SESSION['logged'])) { header("Location: members.php"); } else { header("Location: loginform.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287182 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 here is the part of the code that i need the redirect in its about 3 functions down from the top because the script checks for sessions set and stuff then fires the function if everything is ok. but like i said before i get headers have already been sent errors ...i'm useing php5 function displayLogin(){ global $logged_in; if($logged_in){ echo "<h1>Logged In!</h1>"; echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"http://localhost/secure_php/logout.php\">Logout</a>"; header('Location:http://localhost/logout.php'); } else{ } Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287187 Share on other sites More sharing options...
trq Posted July 1, 2007 Share Posted July 1, 2007 Remove... echo "<h1>Logged In!</h1>"; echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"http://localhost/secure_php/logout.php\">Logout</a>"; The do nothing except invoke the error your recieving. Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287189 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 no matter what error is .....warning cannot modify header information headers already started by output started at c:\webserver\main.php:10 in c:\webserver\login.php on line 99 how the heck do i do this?...i just need it to redirect to another html page after successful login Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287191 Share on other sites More sharing options...
hackerkts Posted July 1, 2007 Share Posted July 1, 2007 Why not just use html meta tag to redirect page? Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287192 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 you can't use echo then header.. read the pinned post for example test1.php//will work <?php header('Location:http://localhost/logout.php'); ?> test2.php //will fail <?php echo "Hello"; header('Location:http://localhost/logout.php'); ?> as your calling a function i guess you are already outputting data to the screen Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287193 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 hmm well we seem to be making some head way now the error is syntax error unexpected : encountered and it refers to the header line i checked the header line and i definately wrote it like this header (Location: 'http://localhost/test.php') Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287201 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 change to header ('Location: http://localhost/test.php') NOTE the ' Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287205 Share on other sites More sharing options...
trq Posted July 1, 2007 Share Posted July 1, 2007 i checked the header line and i definately wrote it like this Well, it should be like this.... header('Location: http://localhost/test.php'); Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287206 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 ffs............doesn't your nic say genious ....of course I included the semicolon....i still get the unexpected colon error Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287214 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 can you post what you have so far! EDIT: did you move the ' (see my last post) Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287216 Share on other sites More sharing options...
trq Posted July 1, 2007 Share Posted July 1, 2007 The problem is not the colon. You had an error because header() expects a string. If your still gettting the error we need to see some code prior to this line. Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287217 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 too much code to post here the login script is 4 php pages with includes connecting the pages and stuff pointing to functions on other pages using stuff like checklogin();........guess i'll just have to figure it out myself or try to fix it myself.......the whole reason i need to do this is because i need to redirect the page to an html page that loads a flash movie clip.........can i embed a flash movie in php ? Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287224 Share on other sites More sharing options...
trq Posted July 1, 2007 Share Posted July 1, 2007 A few lines prior (5-10) is usually sufficient. PHP does not give accurate line numbers in errors. The line number usually just refers to the lline where the parser finally dies. Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287229 Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 ok try this for me testpage.php (NEW FILE) <?php header('Location: http://localhost/test.php'); ?> thats the whole file Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287230 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 ok so this is what the html uses to load flash into a webpage <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/ flash/swflash.cab#version=6,0,29,0\" width=\"350\" height=\"100\"> <param name=\"movie\" value=\"yourMovie.swf\"> <param name=quality value=high> <embed src=\"yourMovie.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/ download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"350\" height=\"100\"></embed> </object> </code> Now how do i get a php to execute that code? Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287233 Share on other sites More sharing options...
calmchess Posted July 1, 2007 Author Share Posted July 1, 2007 I found the answer using include('test.php'); worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/57949-solved-easy-redirect-questionive-read-the-header-threadplz-help/#findComment-287235 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.