Jump to content

Communication Systems


Professor GIBS

Recommended Posts

I am using HTML5, PHP, SQL, and WAMP to attempt this project.


First I have a question about my mailing system I've written; it's fully setup I believe, and tells me it successfully sent yet I never receive the emails? Now, I think that it's because it doesn't recolonize the database, if not can someone spot an error? I am currently using three files to make this simple system, contact.php, mailer.php, and thanks.php.

 

HERE'S 'contact.php':

<body>	<div id="mainBody">		<form class="email" action="mailer.php" method="post">			<p>Name:</p>			<input type="text" name="name" />			<p>E-mail:</p>			<input type="text" name="email" />			<p>Subject:</p>			<input type="text" name="subject" />			<p>Message:</p>			<textarea name="message"></textarea></p>			<input class="send" type="submit" value="Send">		</form>	</div>	<br><br><br><br><br><br><br><br></body>

HERE'S 'mailer.php':

<?php/* Set e-mail recipient */$myemail = "InstruitKMC@gmail.com";/* Check all form inputs using check_input function */$name = check_input($_POST['name'], "Enter your name");$subject = check_input($_POST['subject'], "Enter a subject");$email = check_input($_POST['email']);$message = check_input($_POST['message'], "Write your message");/* If e-mail is not valid show error message */if (!preg_match("/([w-]+@[w-]+.[w-]+)/", $email)){show_error("E-mail address not valid");}/* Let's prepare the message for the e-mail */$message = "Name: $nameE-mail: $emailSubject: $subjectMessage:$message";/* Send the message using mail() function */mail($myemail, $subject, $message);/* Redirect visitor to the thank you page */header('Location: thanks.php');exit();/* Functions we used */function check_input($data, $problem=''){$data = trim($data);$data = stripslashes($data);$data = htmlspecialchars($data);if ($problem && strlen($data) == 0){show_error($problem);}return $data;}function show_error($myError){?><html>	<body>		<div style="color: red; text-align: center;">			<p>We're sorry, '<strong><?php echo $myError; ?></strong>'</p>			<p>Please click the back button, to keep what you've entered.</p>		</div>	</body></html><?phpexit();}?>

HERE'S 'thanks.php':

<body>		<h2 style="color: green; text-align: center">Successfully Sent!</h2>	<div id="mainBody">		<form class="email" action="mailer.php" method="post">			<p>Name:</p>			<input type="text" name="name" />			<p>E-mail:</p>			<input type="text" name="email" />			<p>Subject:</p>			<input type="text" name="subject" />			<p>Message:</p>			<textarea name="message"></textarea></p>			<input class="send" type="submit" value="Send">		</form>	</div>	<br><br><br><br><br><br><br><br></body>

Second, I would like to review my login system; I currently have went through about five different guides, and their either outdated or do not work. I don't know much about SQL Database, but I was wondering if everything would work fine if I hosted this on localhost with WAMP/PHPMyAdmin? Also, if anyone knows of a good, and easy to use guide out there I can use. I liked this one, here, but it simply didn't work. Thanks :).

Link to comment
Share on other sites

Sure as long as a user is logged on to your network. You need to use ipconfig to get the address of the machine that has your wampserver.

Edited by niche
Link to comment
Share on other sites

Sure as long as a user is logged on to your network. You need to use ipconfig to get the address of the machine that has your wampserver.

Okay, I am a newbie to 'my network', do I let them connect by the WAMP server? Also, I went to 'CMD' and typed in 'ipconfig' which numbers am I looking for? Preferably the name, like I found these to seem important, which one?:
IPv4 Address. .Subnet Mask . .Default Gateway
Link to comment
Share on other sites

you'll need the result next to IPv4 Address

 

... and yes, you'd have to give users the login for your network (assuming you have one (and you should)). Users will also have to be in range of your wifi.

Link to comment
Share on other sites

Users will also have to be in range of your wifi.

Okay, thank you. With that said, can I mail it to myself just as a test to see if it is working?

Link to comment
Share on other sites

Yes,

 

If it's not working there could be lots of reasons. I'd start by checking [mail function] in your php.ini file if you haven't sent an email from your localhost.

Edited by niche
Link to comment
Share on other sites

Okay thank you, kind of off topic but this will really help me right now.. I don't really know what to call it, but I keep coping and pasting my header/footer to all pages. I remember reading somewhere you can use JavaScript to link them all back to the original or something? But I was wondering if you could do it in PHP? Thanks, any articles or tutorials would be awesome!

 

 

Wow, did some searching I found this:

<?pinclude 'filename.php';?>

Please let me know if there is a better way. :)

Edited by Professor GIBS
Link to comment
Share on other sites

Okay, I will.. Codecademy obviously teaches you nothing. Uhm, just as some quick help though. I changed all of my code to that. Every page is working except for my folders within a folder. They don't link properly with the images? Any possible solutions?

 

 

*I just added a file named "inner_header", and linked that. Works like a charm, but is there a better way?

Edited by Professor GIBS
Link to comment
Share on other sites

There's probably always a better way. The more code that you write from scratch the better your definition of better will become.

 

I recommend the MVC model as a general thought for anchoring your code:

 

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

 

MVC should be part of a coder's definition of better. Maybe even best.

Link to comment
Share on other sites

MVC is just one of many different programming paradigms. I wouldn't necessarily call it best, just better suited for certain tasks, such as a content management systems where you want to keep presentation separated from the logic.

  • Like 1
Link to comment
Share on other sites

Okay sweet thank you guys, I'm going to look more into it as I get more advanced with web development. But, I have a new problem with the centering of my webpage, and I have a few questions...

 

Okay, so I added a few pages by following this guide, and it works fine except that it is off centered on those pages, but it is running on the same CSS File? I cannot upload all of this to my website that you guys can view, until after school. But, I can explain. First here is my PHP Code for one of the pages:

<!DOCTYPE html><html lang="en">	<head>		<title>CodeMode - Login</title>		<link href="login.css" rel="stylesheet"/>		<script type="text/javascript" src="home.js"></script>        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>        <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>		<link rel="icon" href="../home/images/FAVICON_PICTURE.png" type="image/png" sizes="16x16"/>		<link rel="shortcut icon" href="../home/images/FAVICON_PICTURE.png" type="image/png" sizes="16x16"/>		<meta charset="UTF-8">	</head>	<div><?php include '../transfer/header.php'; ?></div>	<body>		<div class="center" class="margin">			<?php				// check for minimum PHP version				if (version_compare(PHP_VERSION, '5.3.7', '<')) {				    exit('Sorry, this script does not run on a PHP version smaller than 5.3.7 !');				} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {				    // if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php				    // (this library adds the PHP 5.5 password hashing functions to older versions of PHP)				    require_once('libraries/password_compatibility_library.php');				}				// include the config				require_once('config/config.php');								// include the to-be-used language, english by default. feel free to translate your project and include something else				require_once('translations/en.php');								// include the PHPMailer library				require_once('libraries/PHPMailer.php');								// load the login class				require_once('classes/Login.php');								// create a login object. when this object is created, it will do all login/logout stuff automatically				// so this single line handles the entire login process.				$login = new Login();								// ... ask if we are logged in here:				if ($login->isUserLoggedIn() == true) {				    // the user is logged in. you can do whatever you want here.				    // for demonstration purposes, we simply show the "you are logged in" view.				    include("views/logged_in.php");								} else {				    // the user is not logged in. you can do whatever you want here.				    // for demonstration purposes, we simply show the "you are not logged in" view.				    include("views/not_logged_in.php");				}			?>		</div>		<br><br><br><br><br><br><br><br><br>	</body>	<div><?php include '../transfer/footer.php'; ?></div></html>

If I were to take out the whole "<?php // check for minimum PHP version ?>", then it is perfectly centered again? I don't understand, where it's getting its in information from? Please help me understand this? Here's the CSS File:

/*<DELETABLES>*/.center {	text-align: center;	padding: 15px 0px;}#copyright {	font-weight: bold;	text-align: center;}.motto {	text-align: center;	font-size: 16px;	color: #262680;	font-style: italic;}.CodeMode {	font-style: italic;}/*</DELETABLES>*//*<BASIC CSS>*/* {	margin: 0 auto;	background-color: black;	color: #999999;	font-family: Arial, Helvetica, sans-serif, Georgia, serif;}header {	width: 100%;	background-color: black;	padding: 10px 0 50px 0;}body {	width: 960px;	color: #999;	background-color: black;	font-size: 14px;}#footer a {	text-decoration: none;	font-size: 17px;	color: #123ACE;}#footer a:hover {	text-decoration: underline;	color: #000ACE;}/*</BASIC CSS>*//*<LOGIN FORM>*/#login {	height: 150px;	width: 260px;	padding-left: 15px;	padding-right: 15px;	float: right;}.clickButton {	width: 126px;	height: 25px;	margin: 10px 2px 5px 2px;	clear: all;	float: left;}.clickButton:hover {	color: white;	background-color: #080808;	border-top: 1px solid gray;	border-left: 1px solid gray;	border-bottom: 3px solid #777;	border-right: 3px solid #777;}/*</LOGIN FORM>*//*<NAVIGATION BAR>*/nav li:hover ul {	display: block;	box-shadow: 0 1px 8px #777;}nav li ul:hover ul {	display: inline;}nav {	display: block;	position: relative;	border-top: 1px solid black;	border-bottom: 1px solid black;	border-right: 2px solid #222;	font-weight: bold;	font-size: 1.18em;	height: 40px;	width: 99.80%;	margin: 10px auto;	box-shadow: 0 1px 1px #444;	background-image: url("background_logo.jpg");}ul#navigation li:hover > ul {	visibility:visible;	opacity:1;}ul#navigation ul, ul#navigation ul li ul {    visibility: hidden;    opacity: 0;	-webkit-transition: opacity 0.4s linear, visibility 0.4s linear; 	-moz-transition: opacity 0.4s linear, visibility 0.4s linear; 	-o-transition: opacity 0.4s linear, visibility 0.4s linear; 	transition: opacity 0.4s linear, visibility 0.4s linear;}nav li a:hover {	color: white;	text-shadow: 0px 0px 0px #777;	background-image: url("background_logo_hover.jpg");}nav li a {	text-decoration: none;	display: block;	padding: 10px 24px;	border-right: 3px solid #222;	color: #888;	text-shadow: 1px 1px 0px #777;	background-image: url("background_logo.jpg");}#firstNav {	border-left: 3px solid #222;}nav ul {	margin: 0px;	padding: 0px;}nav li {	position: relative;	float: left;	list-style-type: none;}nav ul ul {	position: absolute;	left: 45px;	width: 180px;}nav ul ul:hover {	position: absolute;	left: 45px;	width: 180px;}nav ul ul li {	border: 1px solid #222;	width: 180px;}#special {	position: absolute;	display: block;	left: 182px;	width: 180px;	top: -2px;	visibility: hidden;    opacity: 0;}#special_hover:hover #special {	position: absolute;	display: block;	left: 182px;	width: 180px;	top: -2px;	visibility: visible;    opacity: 1;	-webkit-transition: opacity 0.4s linear, visibility 0.4s linear; 	-moz-transition: opacity 0.4s linear, visibility 0.4s linear; 	-o-transition: opacity 0.4s linear, visibility 0.4s linear; 	transition: opacity 0.4s linear, visibility 0.4s linear;}ul#navigation li a {	-webkit-transition:color 0.4s linear, background 0.4s linear;		-moz-transition:color 0.4s linear, background 0.4s linear;		-o-transition:color 0.4s linear, background 0.4s linear;		transition:color 0.4s linear, background 0.4s linear;	}#FAQ {	text-align: center;}/*</NAVIGATION BAR>*/

Okay so this is the exact file I've used with my homepage, and this page. Along with most others, it should work but I think it's linked with an outer file with the php, but I am not experienced enough to figure it out. Just wondering, what's wrong here?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...