Jump to content

[SOLVED] php login scrip worked but small problem inserting into html


andybrooke

Recommended Posts

Hi i created a logon script in php. it worked perfectly BUT after inserting the Logon php script into the center of a HTML page it did somthing wiered. after you logged in it takes you to the page that says "you are not logged in" and then back to the logon page (as it should if you were not logged on) but then when you repeat the logon it works. it is as if the loading page needs a pause to allow the session to take effect. but no idea really. Can any one help PLEASE, I have a sore head now thinking about why this is.

**(ALSO PLEASE HELP ME IN BASIC ENGLISH AS A TOTAL NOVICE IN PHP AND WONT UNDERSTAND PHP TALK. (sTEP BY STEP IF POSS PLEASE)**

 

THANKS AND SORRY IM THICK!! BUT EVERYONE STARTS SOMETIME

Link to comment
Share on other sites

First things first, if you post for help with your code, it helps to actually post the code.

 

Second, it sounds like you are using Sessions.  If so, you need to set the session prior to output, so make a small change to your page and put

 

<?php

session_start();

?>

 

at the very top.

Link to comment
Share on other sites

hi. sorry here is the logon scrip. I will post the landing page script on the next post!

 

<?php

require 'files/header.inc.php';

 

if ( isset($_SESSION['User']) )

{

echo "You are already logged in.. redirecting\n";

echo "<meta http-equiv=\"refresh\" content=\"1;url=members.php\">\n";

} else {

if ( !isset($_POST['username']) || !isset($_POST['password']) )

{

echo "<br />\n";

echo "<form method=\"post\" action=\"http://www.completedebtsolution.co.uk/index2/index.php\">\n";

echo "Username: <input type=\"text\" name=\"username\"><br />\n";

echo "Password:  <input type=\"password\" name=\"password\"><br />\n";

echo "<input type=\"submit\" value=\"Login\"><br /><br />\n";

 

echo "</form>\n";

 

echo "<a href=\"http://www.completedebtsolution.co.uk/index2/regnow.htm\">Click Here To Register</a>";

} else {

$username = addslashes($_POST['username']);

$password = sha1(addslashes($_POST['password']));

$ret = mysql_query("SELECT * FROM $dbtable WHERE UserName = '$username' AND UserPass = '$password' LIMIT 1");

if (@mysql_num_rows($ret) != 0)

{

$ret = mysql_fetch_array($ret);

$_SESSION['User'] = $ret;

$username = $_SESSION['User']['UserName'];

echo "Welcome Back $username.. redirecting\n";

echo "<meta http-equiv=\"refresh\" content=\"1;url=index2.php\">\n";

} else {

echo "Sorry, Incorrect Login Information\n";

}

}

}

 

 

 

 

?>

Link to comment
Share on other sites

This is the script pasted at the top of each html page. and all pages saved as .PHP

 

<?php

require 'files/header.inc.php';

 

if ( !isset($_SESSION['User']) )

{

echo "You are not logged in.. redirecting\n";

echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">\n";

} else {

if ( isset($_GET['logout']) )

{

$username = $_SESSION['User']['UserName'];

unset($_SESSION['User']);

echo "Goodbye $username.. redirecting\n";

echo "<meta http-equiv=\"refresh\" content=\"1;url=index.php\">\n";

}

}

 

include 'files/footer.inc.php';

 

?>

Link to comment
Share on other sites

Hi the header php (require 'files/header.inc.php';) that the script refers to does include  session_start();  mmmm

 

header script:

<?php

 

session_start();

 

require 'mysql.inc.php';

 

echo "<html>\n<head>\n<title>Total Debt Solutions</title>\n</head>\n<body>\n";

 

?>

Link to comment
Share on other sites

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.