Jump to content

Inheritance


dminder

Recommended Posts

First question:If I have a php document that handles my database connectivity and it has a session_start(); statement in it, will any page that includes that document inherit that line or will it ignore it? If it does in fact inherit it, what type of security issues does it pose? This is the code in my header file:

<?php	session_start();	$dbhost="myhostname@domain.com";	$dbname="database1";	$dbpassword="";		//generate the connection	$con = mysql_connect($dbhost, $dbname, $dbpassword);		//select database	mysql_select_db($dbname, $con);		//function to display an error message.	function showerror(  )   {	  $error=("Error " . mysql_errno(  ) . " : " . mysql_error(  ));   }?>

This would be the start of my other file:

<?php	require_once('dbconnect.php');	//Is this necessary??	session_start();		if (!(isset($_SESSION['login']) && $_SESSION['login'] != '') 			&& $_SESSION['login'] != 'myadminaccount') {		header ("Location: homepage.php");	}

Secondly, if I have a function for showing MYSQL errors in the database connection file that is included, can I still use it to print errors that occur in each page?Thanks....yeah i know n00b :)

Link to comment
Share on other sites

You can think of include and require as if the code was just copied and pasted, that's literally how it ends up working. When you have an include statement that includes a file, it's literally as if you copied and pasted the code in the included file into the place where the include statement is.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...