andybrooke Posted January 23, 2008 Share Posted January 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/ Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447204 Share on other sites More sharing options...
fanfavorite Posted January 23, 2008 Share Posted January 23, 2008 There could be a few reasons. The first is if you are setting the session variable on the same page, the page needs to be reloaded in order to be able to read the variable. If that is not the case, then make sure you have session_start(); at the top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447206 Share on other sites More sharing options...
andybrooke Posted January 23, 2008 Author Share Posted January 23, 2008 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"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447219 Share on other sites More sharing options...
andybrooke Posted January 23, 2008 Author Share Posted January 23, 2008 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'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447221 Share on other sites More sharing options...
andybrooke Posted January 23, 2008 Author Share Posted January 23, 2008 when you just use these scripts they work perfect. but as soon as i inserted them into a html page and renamed page from html to php it works but only on the second login. confused!!!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447223 Share on other sites More sharing options...
andybrooke Posted January 23, 2008 Author Share Posted January 23, 2008 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447225 Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 Then the include file needs to come before the HTML or you need to do what I posted above. Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447229 Share on other sites More sharing options...
andybrooke Posted January 23, 2008 Author Share Posted January 23, 2008 Hi thanks for that, i will try inserting: <?php session_start(); ?> at the top of the page, can i clarify, do i put this at the sart of the logon page or at the start of the laning page of both? Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447242 Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 Every page that requires sessions. Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447254 Share on other sites More sharing options...
andybrooke Posted January 23, 2008 Author Share Posted January 23, 2008 Thank you so much i cant tell you how much a relife that is to solve this problem, I knew it would be a simple solution........ Quote Link to comment https://forums.phpfreaks.com/topic/87439-solved-php-login-scrip-worked-but-small-problem-inserting-into-html/#findComment-447261 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.