last day (14 days later) » 

8:38 AM
0
A: PHP form requires two submit button clicks to disappear

RasclattDestroy session needs to come at the very top of the page. <?php // Start session session_start(); // Destroy here before output of HTML. You should check that it's set first if(isset($_POST['submit']) && $_POST['submit'] == 'Logout') session_destroy(); // Don't hide the logout, just prevent...

 
But I am destroying it after user clicks on Logout. How is this one different?
 
Because you are destroying the session after you print the $_SESSION['login'] to the page so it appears you have not logged out. You will get the same result if you refresh rather than click the logout button again.
 
I got this error Warning: session_destroy(): Trying to destroy uninitialized session
 
Did you set it up exactly as written above? First session_start(), then check for logout, then destroy?
 
Yes, the error is on line 251, the line where I destroy it in my logout form
 
8:38 AM
You don't need to destroy it there if you destroy it at the top of the page. It will have already been destroyed by that point.
 
So, should I just remove this code completely <?php if ($_POST['submit'] == 'Logout'){ session_destroy(); }?>
Hey this works the first time
but If I login and try to logout again, logout never happens
 
Can you post the code for your page?
in an edit?
What I have works, guaranteed, so maybe you have something else going on
 
Should I post complete code from the page?
 
Yes post full page if not too big.
 
Alright
I am posting code after removing all HTML part and scripts
I have posted the code
 
8:51 AM
Well make sure there is enough left to get a good overview of what's happening in your page. There may be something that is interfering with your code.
 
I will post more code if the issue is still undetectable. I suspected that SO won't let me so much code.
 
I think I have enough to go on. Give me a sec to revise
 
Thank you :)
 
9:10 AM
Sorry, The code is complete mess.
 
9:22 AM
Are you there?
 
9:54 AM
Is that mismatch coming from the Login function?
 
Yes, It is coming from there. Should i echo the password to check what is the value there?
Thank you for being so patient.
Yes, It is coming from there. Should i echo the password to check what is the value there?
 
Yeah, echo password.
 
Please wait
 
Somewhere there is a breakdown. Like I say the code is all the same, just broken up to help keep your main page clean and so you can have access to those functions on other pages if need be.
O crap it the $email
 
Would there be any difference If I included the function.php file at different location in index.php
 
10:01 AM
There is also no $email variable
Hold on I will fix.
Ok I fixed that function and where it's applied. See edits.
 
One more mistake I made on this line of the function: $mysqli->query("SELECT * from member WHERE EMAIL = '$email' AND PASSWORD = '$password'");
$email not $checkemail
 
Thanks it is working but logout still takes to button clicks to disappear
Should I mail you a sample email and password to try?
 
Sure.
 
Please wait for sometime
 
10:13 AM
Actually do you have all your code lines in the exact same order as I do because that should not happen.
 
Yes, I have changed nothing except for putting
<?php
before
if(!isset($_SESSION['login'])) { ?>
I have added closing php tag for upper section of PHP code though.
 
So this is how the top of your page goes?
<?php
    // Include the functions that run this page actions
    include_once('functions.php');
    // Start session
    session_start();

    // If logging out, destroy session
    if(isset($_POST['submit']) && $_POST['submit'] == 'Logout')
        session_destroy();
Nothing before that?
 
<?php
$db_hostname = 'hostname';
$db_username = 'username';
$db_password = 'password';
$db_database = 'database';
include_once('../../templates/functions.php');
session_start();
if(isset($_POST['submit']) && $_POST['submit'] == 'Logout')
session_destroy();
$mysqli = new mysqli($db_hostname,$db_username,$db_password,$db_database);
if (isset($_POST['submit']) && $_POST['submit'] == 'Login')
$valid = Login($_POST['password'],$_POST['email'],$mysqli);
if(isset($_POST['submit']) && $_POST['submit'] = 'Register')
This is the order for the code
 
Hmmmm, that all looks fine. I can not see where it would not work as intended.
 
Please wait for a few more seconds. I will mail a dummy email and password
This is the webpage
Email = montishokeen3663@gmail.com
password = 12345
 
10:25 AM
ok let me take a look
 
Could you login?
 
Yeah, I see it. It's definitely strange.
 
Could it be some problem with server?
 
No that is a function of the script. There is still something going on. Look at my new edits.
 
Alright
 
10:36 AM
I have never used a standard function to assign a class, so it may or may not work for the config.php $mysqli
 
What does "so it may or may not work for the config.php $mysqli mean?"
Which part have you edited in the code?
 
I added a config file for your database connection so it can be included and segregated out.
config.php
		function DBConnect($db_hostname = 'host',$db_username = 'username',$db_password = 'password',$db_database = 'dbname')
			{
				// Database
				$mysqli = new mysqli($db_hostname,$db_username,$db_password,$db_database);
				if(mysqli_connect_errno()) {
					printf("Connect failed: %s\n", mysqli_connect_error());
					exit();
				}

				return $mysqli;
			}

		$mysqli	=	DBConnect();
Then this portion at the top of index:
 // Make a db function
        include_once('config.php');
        // Include the functions that run this page actions
        include_once('functions.php');

    	// Start session
        session_start();

		// If logging out, destroy session
    	if(isset($_POST['submit'])) {
			// Logout script
			if($_POST['submit'] == 'Logout')
    			session_destroy();
    		// Run your login script
			elseif($_POST['submit'] == 'Login')
				$valid	=	Login($_POST['password'],$mysqli);
			elseif($_POST['submit'] = 'Register')
 
Please wait, let me edit and tell what happens.
 
Also, is your script being inserted into this page? Like where is that top menu bar and left formatting area on that script of yours?
 
The Share your story stuff?
 
10:42 AM
Yeah
 
It is implemented using tiny MCE Editor
I added their script and go it working
Could I ask where are you from?
 
Oh, ok so it's in the code somewhere, just you haven't added it to this code snippit
I'm from Nevada USA. U?
Well thats where I live. I am actually from Canada
 
I am from India :)
It is 04:15 there but you are awake?
 
It's only 2:45am here...but yes. After this I am going to bed. See the comment by DarkBee.
 
I have added the code.
Should I keep
if(isset($_GET['passkey']) && !empty($_GET['passkey'])){
echo (FetchPassKey($mysqli) == true)? "Your account has been activated":"Wrong Confirmation code";
}
 
10:49 AM
Yeah all the code is still good.
 
This code in index.php
Hey, Thanx for being so helpful
 
Let me fix the part that should fix the session refresh.
 
What's ur age? I am 20.
I don't think I completely understood your last comment on the question
 
I'm an oldy. 38. Here is the part with the change as suggested by DarkBee:
// If logging out, destroy session
    	if(isset($_POST['submit'])) {
			// Logout script
			if($_POST['submit'] == 'Logout') {
    				session_destroy();
					header("Location: ".$_SERVER['PHP_SELF']);
					exit;
				}
    		// Run your login script
			elseif($_POST['submit'] == 'Login')
				$valid	=	Login($_POST['password'],$mysqli);
			elseif($_POST['submit'] = 'Register')
	    		$registered	=	Register($mysqli);
		}
Notice the header(); portion.
it will reload the page when session destroyed.
 
Got it :)
I tried something similar earlier but got headers already sent error
let me try again
I am getting Entered Password and Email Combination is wrong!
again
 
11:05 AM
Noooooooooo.....hold on let me look at it
print_r($mysqli); and see if it comes out as an object
 
Ok, where should I write it?
elseif($_POST['submit'] == 'Login')
$valid = Login($_POST['password'],$mysqli);
I edited
to
elseif($_POST['submit'] == 'Login')
$valid = Login($_POST['password'],$_POST['email'],$mysqli);
 
Make sure if you use that DBConnect function, you have proper db credentials in the function prefs
 
Yes they are all correct.
 
print_r($mysqli); at the top of the page after the function include
 
I got this
mysqli Object ( [affected_rows] => 0 [client_info] => 5.0.51a [client_version] => 50051 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 0 [host_info] => apnasikkacom.ipagemysql.com via TCP/IP [info]
=> [insert_id] => 0 [server_info] => 5.5.32-log [server_version] => 50532 [stat] => Uptime: 9067197 Threads: 15 Questions: 7861454470 Slow queries: 16151 Opens: 84767313 Flush tables: 1 Open tables: 2048 Queries per second avg:
867.021 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 175687041 [warning_count] => 0 ) Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /hermes/bosnaweb04a/b2659/ipg.apnasikkacom/8mags/bored/people/index.php:4) in /hermes/bosnaweb04a/b2659/ipg.apnasikkacom/8mags/bored/people/index.php on line 5
Here are first five lines of index.php
<?php
include_once('../../templates/config.php');
include_once('../../templates/functions.php');
print_r($mysqli);
session_start();
 
11:11 AM
Ok it looks like your connection is working and has no errors. Since you are print_r($mysqli), you will get the header error
You can delete the print_r($mysqli) now. I just wanted to make sure your connection was being sent to the $mysqli from the DBConnect function.
O crap, you are right, I forgot to paste the login function back in properly...
$valid = Login($_POST['password'],$_POST['email'],$mysqli);
 
I corrected that but still got Password mis-match error
 
Well then i really am confused. Check the $_POST['email'] and $_POST['password '] and see if they are being populated properly
 
Ok, I will echo them.
echo password gave 12345
and echo email gave montishokeen3663@gmail.com
I echoed them with this code
elseif($_POST['submit'] == 'Login')
{
echo $_POST['password'];
echo $_POST['email'];
$valid = Login($_POST['password'],$_POST['email'],$mysqli);
}
Could it be a problem with hash?
 
I don't see why. Nothing has changed there.
echo your SQL statement and see what it says
Ohhh son of a gun! Just kidding. Ok great!
 
Hey, sorry
It is working I entered wrong password last time.
Sorry again.
Thank you
very much.
You are awesome :)
 
11:23 AM
So is it all working now?
 
I would have never figured out how to get it working
Yes, everything is working fine for now.
If i use this code on other pages will it still work
 
Yeah, to be honest DarkBee reminded me of the header() redirect
 
Still you were patient enough to be with me for so long.
Almost everyone would have gave up
Suppose I put this code
 
Yeah, if you include the config file and the functions page, you can use them on those pages.
 
on my home page
and a user logs in from home page then visits this page
will he still be logged in?
When I tried it last time
it did not work
 
11:25 AM
If you put the session_start() on the config.php page and include that on any page in your site, the session will persist
So:
 
So, I have to keep this code intact
<?php
include_once('../../templates/config.php');
include_once('../../templates/functions.php');
session_start();
if(isset($_POST['submit'])) {
 
<?php
function DBConnect($db_hostname = 'host',$db_username = 'username',$db_password = 'password',$db_database = 'dbname')
{
// Database
$mysqli = new mysqli($db_hostname,$db_username,$db_password,$db_database);
if(mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

return $mysqli;
}
session_start();
$mysqli = DBConnect(); ?>
Then remove session_start(); off the index page.
 
I have changed my config file to what you have provided here. Could you please wait for a few more minutes for me to check?
 
Sure, just make sure you remove the session_start(); off any page you include the config page or else you will get a session already started error
 
Ok I will do that.
 
11:30 AM
ok. Let me know if it works on the other pages and then I will go to bed. :D
zzzzzzzzzzzzzzzzzzz
 
Are you gone?
Hey, Can I send you a friend reuqest on Facebook to be in contact?
Warning: session_destroy(): Trying to destroy uninitialized session in /hermes/bosnaweb04a/b2659/ipg.apnasikkacom/8mags/bored/people/index.php on line 7 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosnaweb04a/b2659/ipg.apnasikkacom/8mags/bored/people/index.php:7) in /hermes/bosnaweb04a/b2659/ipg.apnasikkacom/8mags/bored/people/index.php on line 8
I got this error
 
Did you add the session_start(); to the config page?
 
Yes, I added that. Hey we can talk later. You should go to bed.
Is there any other way to contact you?
<?php
function DBConnect($db_hostname = 'apnasikkacom.ipagemysql.com',$db_username = 'stories8mags',$db_password = '1q2w3e!@',$db_database = 'stories8mags')
{
// Database
$mysqli = new mysqli($db_hostname,$db_username,$db_password,$db_database);
if(mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

return $mysqli;
session_start();
}

$mysqli = DBConnect();
?>
This is my config.php file
 
Oh, no, don't put it in the function. Put it right before the $mysqli = DBConnect();
So should be:
}

session_start();
$mysqli = DBConnect();
not:
session_start();
}

$mysqli	=	DBConnect();
 
Thank you it is working now.
:)
Good night
 
11:42 AM
Ok great! Not to be a pain, but don't forget to mark my answer correct! I need that +15 :D
Cheers, talk to you later!
 
Sure I will :)
Alright
Done
 

last day (14 days later) »