Jump to content

I looked everywhere I could,, but couldn't find the answer to this.


Recommended Posts

Well, something went wrong with my script and I am back to the same problem as before. My error message for my login displays on the same page as my form. Which is good,,, but it also throws the error message up in the url box on my browser.  the code for my login script is below.

<?php[code]
// display log in error or success
if($count==1)
{
session_start();
$_SESSION['auth'] = "yes";
$message = "Welcome $username";
header("location: home.php?error=" . urlencode($message));
}
else 
{
$message = "$username is not a registered username.";
header("location: index.php?error=" . urlencode($message));
}

?> 

here is the code that echos the error message

<? echo $_GET['error'];?>

and this is what is in my url box on my browser.

http://----------.com/index.php?error=fdsaf+is+not+a+registered+username.

i guess my question is,, why is it displaying this in the url box of my browser?

Well,,, were getting there... If the name entered is not valid then the $_SESSION['error'] is displayed properly... as for when the name entered and it is a valid username... I am using $_SESSION['auth'] to check that the user is logged in so they can go to the members only page.... So for the success message, what should i use instead of $_SESSION.

Nevermind,,, now I am confused. This is what I thought would work.

<?php
// display log in error or success
if($count==1)
{
session_start();
$_SESSION['auth'] = "yes";
header("location: home.php");
$_SESSION['success'] = "Welcome $username"; 
}
else 
{
session_start();
header("location: index.php");
$_SESSION['error'] = "$username is not a registered username.";
}
?> 

and then for my success or error message

<?php
<?php echo $_SESSION['success'];?> //this is located on the members page
<?php echo $_SESSION['error'];?>  //located on the page with the form
?>

<?php

  session_start();

// display log in error or success
if($count==1)
{
$_SESSION['auth'] = TRUE;
$_SESSION['message'] = "Welcome ".$username;
echo "<script>window.location='home.php'</script>";/* you can use header i just prefer JS */
}
else 
{
$_SESSION['auth'] = FALSE;
$_SESSION['message'] = $username." is not a registered username.";
echo "<script>window.location='index.php'</script>";
}

?> 

Alright,, the error messages now display properly... Thank you everyone... Here is what ended up working for me..

<?php     //login
if($count==1)
{
session_start();
$_SESSION['auth'] = "yes";
$_SESSION['message'] = "Welcome ".$username;
header("location: http://www.-------------.com/home.php");
}
else 
{
session_start();
$_SESSION['message'] = $username." is not a registered username.";
header("location: http://www.-----------.com");
session_destroy();
}

?> 
Would something like session_unset['message'] on refresh work?

and then the code that goes where you want the message to appear.

<?php if(isset($_SESSION['message'])){echo $_SESSION['message'];} ?>

Everything works good except one small thing..... If someone enters an invalid username the message appears on the page,, which is good... When I hit the refresh button on my browser the message stays there... What should I do to get rid of the session error message when the browser is refreshed????

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.