Tokae Posted April 23, 2012 Share Posted April 23, 2012 Hello all, I am trying to get a simple members.php page to show some HTML but I cannot figure out why it will not display.. <?php mysql_connect("myserver", "myname", "mypass") or die(mysql_error()); mysql_select_db("mydb") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM Users WHERE name = '$name'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($password != $info['password']) { header("Location: login.php"); } else { ?> <html> <body> <h1>WHY</h1> </body> </html> <?php } } } else { header("Location: login.php"); } ?> I was googling and read somewhere that it might be a session bug after the initial '<?php tag'? Any help would be greatly appreciated Tokae Link to comment https://forums.phpfreaks.com/topic/261503-html-within-php-not-showing/ Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 You shouldn't store the password in a cookie. In any form. Ever. It's hard to test your script, because I'll always be redirected. When I test your script, with your specific lines commented out and the conditionals set to output the HTML, everything looks fine for me <?php //mysql_connect("myserver", "myname", "mypass") or die(mysql_error()); //mysql_select_db("mydb") or die(mysql_error()); if(TRUE) { //$username = $_COOKIE['ID_my_site']; //$pass = $_COOKIE['Key_my_site']; //$check = mysql_query("SELECT * FROM Users WHERE name = '$name'")or die(mysql_error()); $loop = TRUE; while( $loop ) { if ( FALSE ) { echo 'directed to login.php'; } else { ?> <html> <body> <h1>WHY</h1> </body> </html> <?php } $loop = FALSE; // stop infinite loop } } else { echo 'directed to login.php'; } ?> Output <html> <body> <h1>WHY</h1> </body> </html> So, I've come to the conclusion there's something wrong with the data you're getting from cookies or from the database. Since I can't verify either, you're going to have to yourself, using echo or other means. Link to comment https://forums.phpfreaks.com/topic/261503-html-within-php-not-showing/#findComment-1339951 Share on other sites More sharing options...
Tokae Posted April 23, 2012 Author Share Posted April 23, 2012 Thank you for the quick response! How would you suggest I check to make sure the proper user is still logged in, instead of storing the info in cookies.. Link to comment https://forums.phpfreaks.com/topic/261503-html-within-php-not-showing/#findComment-1339954 Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 The easiest way would be to use PHP sessions. A unique token is created for the user, and that token is stored in a cookie. The token can then be used to reference any data linked to it. There's TONS of tutorials on the web on how to use PHP sessions. Link to comment https://forums.phpfreaks.com/topic/261503-html-within-php-not-showing/#findComment-1339956 Share on other sites More sharing options...
Tokae Posted April 23, 2012 Author Share Posted April 23, 2012 Thank you once again! I will check up on sessions.. Link to comment https://forums.phpfreaks.com/topic/261503-html-within-php-not-showing/#findComment-1339959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.