Drezard Posted September 15, 2006 Share Posted September 15, 2006 Need alittle help. Cant redirect script. Im kinda new to redirecting scripts.Heres the error:[QUOTE]Parse error: syntax error, unexpected '<' in C:\Program Files\xampp\htdocs\login_form.php on line 35[/QUOTE]Heres the script:[CODE]<?php// initialize a sessionsession_start();?><html><head></head><body><?phpif (!isset($_SESSION['login']) && !isset($_POST['user'])) { // if no data, print the form?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> Username:<input type="text" name="user"><br> Password:<input type="password" name="pass"><br> <input type="submit" name="submit"> </form><?php}else if (!isset($_SESSION['login'])) { include('connect.php'); // if a session does not exist but the form has been submitted // check to see if the form has all required values // create a new session $user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']); $pass = empty($_POST['pass']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass']); $sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['userinfo'] = $user; <meta http-equiv="refresh" content="0;url=login_sucess.php">; } if ($count == 0) { echo "Username or password are incorrect"; } }?></body></html>[/CODE]Thanks, Daniel Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/ Share on other sites More sharing options...
Orio Posted September 15, 2006 Share Posted September 15, 2006 Change this:<meta http-equiv="refresh" content="0;url=login_sucess.php">;Toecho <meta http-equiv="refresh" content="0;url=login_sucess.php">;Orio. Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92273 Share on other sites More sharing options...
Drezard Posted September 15, 2006 Author Share Posted September 15, 2006 I worked out what the problem was but now i got another one:[QUOTE]Parse error: syntax error, unexpected $end in C:\Program Files\xampp\htdocs\login_sucess.php on line 21[/QUOTE]Heres the script:[CODE]<?php// initialize a sessionsession_start();?><html><head></head><body><?phpif (!isset($_SESSION['login']) && !isset($_POST['user'])) { // if no data, print the form?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> Username:<input type="text" name="user"><br> Password:<input type="password" name="pass"><br> <input type="submit" name="submit"> </form><?php}if (!isset($_SESSION['login'])) { include('connect.php'); // if a session does not exist but the form has been submitted // check to see if the form has all required values // create a new session $user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']); $pass = empty($_POST['pass']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass']); $sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['userinfo'] = $user; ?> <meta http-equiv="refresh" content="0;url=login_sucess.php">; <?php } if ($count == 0) { echo "Username or password are incorrect"; } }}?></body></html>[/CODE]- Cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92274 Share on other sites More sharing options...
HuggieBear Posted September 15, 2006 Share Posted September 15, 2006 Try removing one of the [color=red][b]}[/b][/color] from the end of the file.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92279 Share on other sites More sharing options...
Drezard Posted September 16, 2006 Author Share Posted September 16, 2006 Hello, I have a problem with session_destroy, Im not sure what ive done wrong.Heres the error:[QUOTE]Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\Program Files\xampp\htdocs\login_sucess.php on line 4[/QUOTE]Heres the script:[CODE]<?php$user = $_SESSION['username'];setcookie('user', $user, time()+36000*24*365);session_destroy();?><head></head><body><?phpif (isset($_COOKIE['user'])) {echo "Login Complete";}?></body></html>[/CODE]- Thanks, Daniel Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92820 Share on other sites More sharing options...
markbett Posted September 16, 2006 Share Posted September 16, 2006 did you start the session before you tried to destroy it? you can derstroy somethign that never existed Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92848 Share on other sites More sharing options...
Drezard Posted September 16, 2006 Author Share Posted September 16, 2006 But what happens if i started it on a page before?- Cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92868 Share on other sites More sharing options...
HuggieBear Posted September 16, 2006 Share Posted September 16, 2006 You have to specify session_start() on every page. Before any code is output to the browser.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/20846-script-not-working/#findComment-92888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.