Jump to content

HTML within PHP not showing


Tokae

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

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