Jump to content

[SOLVED] easy redirect question...i've read the header thread..plz help


calmchess

Recommended Posts

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?

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");
  }

?>

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{

}

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 :(

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

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')

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 ?

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?

Archived

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

×
×
  • Create New...

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.