Jump to content
Killersites Forums

dhahlen

Member
  • Posts

    20
  • Joined

  • Last visited

dhahlen's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. On the last module! I am just trying to get the NSlookup function to work, it will work if I do not use the $_GET variable. If I just specify a domain (cnn.com) it will work fine. if I try to request data, the page thinks until it times out. <?php if(isset($_POST['postBack'])) try { { echo '<pre>'; passthru('nslookup' . $_GET["nslookup"]); echo '</pre>'; } } catch(Exception $e) { echo "<h1 style=\"color:red;\">" . $e->getMessage() . "</h1>"; } ?> Form data: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="nslookup" input type="text" size="10"><br> <input name="postBack" type="hidden" value="yes"> <input type="submit" value="Perform Lookup"> The problem I think I am having is this: The passthru command sends the specified line to the server (i.e. not running it in php any longer). Since the actual server has no clue what $_GET is, it simply displays the results of nslookup and does not display the information from the form. That being said, what I need to do is have the text from the form be input into the pass through command before it is executed on the server. Maybe something like this: Type domain in form --> submit --> php takes $_GET["nslookup"] data and then places the data into passthru("nslookup xxxxxx") where xxxxx is the value of $_GET["nslookup"] --> server executes command --> data displayed on page Any ideas?
  2. I am now working with Exceptions. The goal here is to throw a catch/try block in 3 different sections. Here is an example provided: //A function that throws an exception, for the example only function TryThis() { throw new Exception("I tried it, but it didn't work"); } try { TryThis(); } catch(Exception $e) { echo "An error occured with the following error<br />" . $e->getMessage(); } Prints An error occured with the following error I tried it, but it didn't work A couple of questions: Question 1: Can you use regex inside of OOP? (lets say I want to validate the format of an name or e-mail address. If it's not in the correct format, then throw an exception, then display a message with the catch) I already have regular expressions in place to validate the e-mail, but I'd like to have it thrown an exception instead. Here is the code I use to validate e-mail: <?php $stringSubject = $_POST['txtSubject']; $stringSubject = str_ireplace("Estrella Mountain","EMCC",$stringSubject); $stringMessage = $_POST['txtMsg']; $stringMessage = str_ireplace("Estrella Mountain","EMCC",$stringMessage); $validemail = $_POST['txtEmail']; $myemailpattern = '^[a-zA-Z0-9\.-_]{1,}@[a-zA-Z0-9\.-_]{1,}(.com|.net|.edu){1}'; if(eregi($myemailpattern,$validemail)) { if(isset($_POST['txtEmail']) && isset($_POST['txtSubject']) && isset($_POST['txtMsg'])) { $from = "From: " . $_POST['txtEmail'] . "\r\n"; $subject = $stringSubject; $msg = $stringMessage; $result = mail('djwampus@gmail.com',$subject,$msg,$from); if($result) { echo "Your email was successfully sent with the following information<br />"; echo "Email Address: " . $from . "<br />"; echo "Subject: " . $subject . "<br />"; echo "Message: " . $msg . "<br />"; } else { echo "<h1 style=\"color:red;\">An error occured sending the email!</h1>"; } } else { echo "<h1 style=\"color:red;\">All fields must be filled out!</h1>"; } } else { echo "<h1 style=\"color:red;\">Invalid E-mail Address</h1>"; } ?> Question 2: in the example provided below, they use $value >=0 && $value <=23) - is there anyway to change it so it uses characters versus numbers? For example ($value = '^[a-zA-Z0-9\.-_]{1,}') Thanks
  3. logout.php <?php session_destroy(); // then use the header function to redirect the user header("location: module8.php"); ?> form.php <html> <?php // added include_once("login_class.php"); // added if (isset($_SESSION['loggedin'])) // added { header("location: loggedin.php"); // added } ?> <head> <style type="text/css"> /* Style Code referenced from http://www.webreference.com/programming/css_frames/index.html */ /* Below are the CSS styles which are referenced throughout the webpage */ body { margin:0; border:0; pading:0; height:100%; background:#eee; font-family:arial, verdana, sans-serif; font-size:76%; overflow: hidden; } #header { position:absolute; top:0; left:0; width:100%; height:100px; overflow:auto; text-align:center; background:#53829d; color:#fff; } #footer { position:absolute; bottom:0; left:0; width:100%; height:50px; overflow:auto; text-align:center; /* Aligns the footer text to the center */ background:#73a2bd; } #contents { position:fixed; top:100px; /* This allows the contents of the body to miss the header position */ left:0; bottom:50px; /* This allows the contents of the body to miss the footer position */ right:0; overflow:auto; /* Adds scroll bars if needed */ background:#fff; } /* navlist referenced from http://css.maxdesign.com.au/listamatic/horizontal01.htm */ #navlist li { display: inline; list-style-type: none; padding-right: 20px; } /* Defines the width of the paragraphs */ p {width:500px;} /* for internet explorer */ * html body { padding:120px 0 50px 0; } * html #contents { height:100%; width:100%; } </style> </head> <body> <div id="header"> <?php echo "<h1>Welcome to Darren's Website</h1>";?> <?php echo "<h2>This line uses h2 style with php</h2>";?> </div> <div id="footer"> <h3>Test Footer using h3, aligned center</h3> </div> <div id="contents"> <div id="navcontainer"> <ul id="navlist"> <li id="active"><a href="http://cis166.estrellamountain.edu/DARUP97011/module8.php" id="current">Home</a></li> <li><a href="guestbook.php">Guest Book</a></li> <li><a href="guestbookwrites.php">Guest Book Writes</a></li> <li><a href="mailto:DARUP97011@maricopa.edu">Contact Me</a></li> <li><a href="contents.txt">Page Code</a></li> <li><a href="mailform.php">E-mail Form</a></li> <li><a href="login.php">Login Page</a></li> </ul> </div> <h1>Contents of the Body goes here, using h1 style</h1> <p> Today's Date is <?php echo date("m-d-Y");?> <p> <h2>Login Example</h2> <form action="" method="post"> <!-- leaving the action attribute blank will cause the page to redirect to itself when the submit button is clicked --> <div> <label for="username">Username:</label> <input name="username" id="username" type="text"> <br/> <label for="password">Password:</label> <input name="password" id="password" type="text"> <br/> <input name="submit" value="Login" type="submit"> </div> </form> </body> </html> login.php I tried this with and without the if (isset($_SESSION['loggedin'])) { header("location: module8.php"); } it yielded the same results. Here is how it sits on the server <?php session_start(); include_once("login_class.php"); $login = new Login(); if (isset($_SESSION['loggedin'])) { header("location: module8.php"); } if (isset($_POST['submit'])) // this checks if the submit button has been clicked { // if so, process the form $login->processForm(); } else { // if the button hasn't been clicked, show the form $login->generateForm(); } ?> <p> </body> </html>
  4. added this logout.php <?php session_destroy(); // then use the header function to redirect the user header("location: module8.php"); ?> When I was clicking on the login page link (form.php) it would keep cycling through the logged in page and the form page (some type of loop, every click would be one or the other, alternating) I moved the logout page to move me to module8.php, and I included this code above form.php <?php session_start(); include_once("login_class.php"); $login = new Login(); if (isset($_SESSION['loggedin'])) { header("location: loggedin.php"); } ?> Now, it seems like the session is not getting destroyed....
  5. Ahh, good to know. Removing that ! would redirect a user if they were logged into the session, doing the opposite of what it does currently.
  6. Everything appears to be working, which now has me curious on the session_destroy() command If we go to anywhere on the page, the session is active. If I click the login page again, can I make an option that says "Already Logged in, click here to log out" and then have the log out link perform a session_destroy() ? This isn't a requirement, but it would be useful in a situation such as this. If someone is logged it and then went to the login page, in most real world scenarios it would tell you the user is already logged in. Also, I understand that we'd normally be authenticating against something like sql or database, versus the method we've completed here. Thanks for all your help, I'm sure I'll be asking more questions as things progress.
  7. Ignore the repetitive css code, I really should create a style page to eliminate all the excess code.
  8. login_class.php <?php class login { var $username = "admin"; var $password = "password"; function __construct() // constructor, PHP5 only { // if you need to do anything when the object is first created, place that code here } function generateForm() { include("form.php"); } function processForm() { if($_POST['username']==$this->username && $_POST['password']==$this->password) { $_SESSION['loggedin'] = TRUE; } else { // show the form using generateForm() function $this->generateForm(); } } function checkLogin($redirect) { // would check if the correct $_SESSION variable is set. If so, user is valid // and can view the requested page. If not, redirect the user using the header() // function to whatever $redirect is set to if (!isset($_SESSION['loggedin'])) { // redirect user header("location: module8.php"); } else { // redirect if user is not logged in header("location: " . $redirect); } } } ?> login.php <html> <head> <style type="text/css"> /* Style Code referenced from http://www.webreference.com/programming/css_frames/index.html */ /* Below are the CSS styles which are referenced throughout the webpage */ body { margin:0; border:0; pading:0; height:100%; background:#eee; font-family:arial, verdana, sans-serif; font-size:76%; overflow: hidden; } #header { position:absolute; top:0; left:0; width:100%; height:100px; overflow:auto; text-align:center; background:#53829d; color:#fff; } #footer { position:absolute; bottom:0; left:0; width:100%; height:50px; overflow:auto; text-align:center; /* Aligns the footer text to the center */ background:#73a2bd; } #contents { position:fixed; top:100px; /* This allows the contents of the body to miss the header position */ left:0; bottom:50px; /* This allows the contents of the body to miss the footer position */ right:0; overflow:auto; /* Adds scroll bars if needed */ background:#fff; } /* navlist referenced from http://css.maxdesign.com.au/listamatic/horizontal01.htm */ #navlist li { display: inline; list-style-type: none; padding-right: 20px; } /* Defines the width of the paragraphs */ p {width:500px;} /* for internet explorer */ * html body { padding:120px 0 50px 0; } * html #contents { height:100%; width:100%; } </style> </head> <body> <div id="header"> <?php echo "<h1>Welcome to Darren's Website</h1>";?> <?php echo "<h2>This line uses h2 style with php</h2>";?> </div> <div id="footer"> <h3>Test Footer using h3, aligned center</h3> </div> <div id="contents"> <div id="navcontainer"> <ul id="navlist"> <li id="active"><a href="http://cis166.estrellamountain.edu/DARUP97011/module8.php" id="current">Home</a></li> <li><a href="guestbook.php">Guest Book</a></li> <li><a href="guestbookwrites.php">Guest Book Writes</a></li> <li><a href="mailto:DARUP97011@maricopa.edu">Contact Me</a></li> <li><a href="contents.txt">Page Code</a></li> <li><a href="mailform.php">E-mail Form</a></li> <li><a href="login.php">Login Page</a></li> </ul> </div> <h1>Contents of the Body goes here, using h1 style</h1> <p> Today's Date is <?php echo date("m-d-Y");?> <p> <?php session_start(); include_once("login_class.php"); $login = new Login(); if (isset($_POST['submit'])) // this checks if the submit button has been clicked { // if so, process the form $login->processForm(); } else { // if the button hasn't been clicked, show the form $login->generateForm(); } ?> <p> </body> </html> loggedin.php <html> <head> <style type="text/css"> /* Style Code referenced from http://www.webreference.com/programming/css_frames/index.html */ /* Below are the CSS styles which are referenced throughout the webpage */ body { margin:0; border:0; pading:0; height:100%; background:#eee; font-family:arial, verdana, sans-serif; font-size:76%; overflow: hidden; } #header { position:absolute; top:0; left:0; width:100%; height:100px; overflow:auto; text-align:center; background:#53829d; color:#fff; } #footer { position:absolute; bottom:0; left:0; width:100%; height:50px; overflow:auto; text-align:center; /* Aligns the footer text to the center */ background:#73a2bd; } #contents { position:fixed; top:100px; /* This allows the contents of the body to miss the header position */ left:0; bottom:50px; /* This allows the contents of the body to miss the footer position */ right:0; overflow:auto; /* Adds scroll bars if needed */ background:#fff; } /* navlist referenced from http://css.maxdesign.com.au/listamatic/horizontal01.htm */ #navlist li { display: inline; list-style-type: none; padding-right: 20px; } /* Defines the width of the paragraphs */ p {width:500px;} /* for internet explorer */ * html body { padding:120px 0 50px 0; } * html #contents { height:100%; width:100%; } </style> </head> <body> <div id="header"> <?php echo "<h1>Welcome to Darren's Website</h1>";?> <?php echo "<h2>This line uses h2 style with php</h2>";?> </div> <div id="footer"> <h3>Test Footer using h3, aligned center</h3> </div> <div id="contents"> <div id="navcontainer"> <ul id="navlist"> <li id="active"><a href="http://cis166.estrellamountain.edu/DARUP97011/module8.php" id="current">Home</a></li> <li><a href="guestbook.php">Guest Book</a></li> <li><a href="guestbookwrites.php">Guest Book Writes</a></li> <li><a href="mailto:DARUP97011@maricopa.edu">Contact Me</a></li> <li><a href="contents.txt">Page Code</a></li> <li><a href="mailform.php">E-mail Form</a></li> <li><a href="form.php">Login Page</a></li> </ul> </div> <h1>Contents of the Body goes here, using h1 style</h1> <p> Today's Date is <?php echo date("m-d-Y");?> <p> This page uses a combination of html, php, and CSS. All styles are handled by CSS, as well as the navigation menu, header and footer. The page is written in HTML, but is excuted on the server end using php. I have left examples as to what certain header and text formatting look like. The code will also reference pages I have used. I've also provided links for them below. </p> <p> <a href="http://css.maxdesign.com.au/listamatic/horizontal01.htm">Navigation Menu CSS Code referenced here</a> <p> <a href="http://www.webreference.com/programming/css_frames/index.html">CSS Styles referenced here</a> <p> <?php session_start(); include_once("login_class.php"); $login = new Login(); $login->checkLogin('login.php'); ?> You're logged in! </body> </html> form.php <html> <head> <style type="text/css"> /* Style Code referenced from http://www.webreference.com/programming/css_frames/index.html */ /* Below are the CSS styles which are referenced throughout the webpage */ body { margin:0; border:0; pading:0; height:100%; background:#eee; font-family:arial, verdana, sans-serif; font-size:76%; overflow: hidden; } #header { position:absolute; top:0; left:0; width:100%; height:100px; overflow:auto; text-align:center; background:#53829d; color:#fff; } #footer { position:absolute; bottom:0; left:0; width:100%; height:50px; overflow:auto; text-align:center; /* Aligns the footer text to the center */ background:#73a2bd; } #contents { position:fixed; top:100px; /* This allows the contents of the body to miss the header position */ left:0; bottom:50px; /* This allows the contents of the body to miss the footer position */ right:0; overflow:auto; /* Adds scroll bars if needed */ background:#fff; } /* navlist referenced from http://css.maxdesign.com.au/listamatic/horizontal01.htm */ #navlist li { display: inline; list-style-type: none; padding-right: 20px; } /* Defines the width of the paragraphs */ p {width:500px;} /* for internet explorer */ * html body { padding:120px 0 50px 0; } * html #contents { height:100%; width:100%; } </style> </head> <body> <div id="header"> <?php echo "<h1>Welcome to Darren's Website</h1>";?> <?php echo "<h2>This line uses h2 style with php</h2>";?> </div> <div id="footer"> <h3>Test Footer using h3, aligned center</h3> </div> <div id="contents"> <div id="navcontainer"> <ul id="navlist"> <li id="active"><a href="http://cis166.estrellamountain.edu/DARUP97011/module8.php" id="current">Home</a></li> <li><a href="guestbook.php">Guest Book</a></li> <li><a href="guestbookwrites.php">Guest Book Writes</a></li> <li><a href="mailto:DARUP97011@maricopa.edu">Contact Me</a></li> <li><a href="contents.txt">Page Code</a></li> <li><a href="mailform.php">E-mail Form</a></li> <li><a href="login.php">Login Page</a></li> </ul> </div> <h1>Contents of the Body goes here, using h1 style</h1> <p> Today's Date is <?php echo date("m-d-Y");?> <p> <h2>Login Example</h2> <form action="" method="post"> <!-- leaving the action attribute blank will cause the page to redirect to itself when the submit button is clicked --> <div> <label for="username">Username:</label> <input name="username" id="username" type="text"> <br/> <label for="password">Password:</label> <input name="password" id="password" type="text"> <br/> <input name="submit" value="Login" type="submit"> </div> </form> </body> </html>
  9. Even with the session_start(); located in login.php, loggedin.php, it still does not redirect. I couldn't simplify it and set the else statement under the processForm to redirect to another page... but for the sake of understanding, I really want to know why it's not working. How long does the session stay active? I know it's a browser session, so it's temporary. Thanks for the info on that $redirect, it still confuses me how it checks a file within a file and then that file references another file, this is why I get lost, stuff is going on all over the place.
  10. It seems to be getting hung up somewhere, it generates the form if the user/pass is not correct, but it does not redirect. Also, I do not understand the $redirect syntax if the user is not logged in, it performs $redirect, but I do not see where this is defined? If I end up putting the header("location: module8.php") under the $_SESSION['loggedin'] = TRUE, I know it's working. Something is happening where the checkLogin function is not properly redirecting to the page
  11. Well, the login portion works (great!) but it keeps failing when I try to call the generateForm function I thought you could call a function by it's name.... see below <?php class login { var $username = "admin"; var $password = "password"; function __construct() // constructor, PHP5 only { // if you need to do anything when the object is first created, place that code here } function generateForm() { include("form.php"); } function processForm() { if($_POST['username']==$this->username && $_POST['password']==$this->password) { $_SESSION['loggedin'] = TRUE; // inserted the header here rather than using isset below // if i remove the header line blow the page will not forward therefore // something else is wrong with the code header("location: " . ' module8.' .'php '); } else { // show the form using generateForm() function // this is also not working generateForm(); } } function checkLogin($redirect) { // would check if the correct $_SESSION variable is set. If so, user is valid // and can view the requested page. If not, redirect the user using the header() // function to whatever $redirect is set to if (!isset($_SESSION['loggedin'])) { // redirect user header("location: " . module8.' .'php '); } else { // Another call to the form which probably does not work generateForm(); } } } ?>
  12. <?php class login { var $username = "admin"; var $password = "password"; function __construct() // constructor, PHP5 only { // if you need to do anything when the object is first created, place that code here } function generateForm() { include("form.php"); } function processForm() { if($_POST['username']==$this->username && $_POST['password']==$this->password) { session_start(); $_SESSION['login']="loggedin"; } // set session variable // redirect user using header() function -- see checkLogin() function for example else { // show the form using generateForm() function header("location: " . login.php); } } function checkLogin($redirect) { // would check if the correct $_SESSION variable is set. If so, user is valid // and can view the requested page. If not, redirect the user using the header() // function to whatever $redirect is set to if (!isset($_SESSION['loggedin'])) { // redirect user header("location: " . module8.php); } else { header("location: " . login.php); } } } ?>
  13. Maybe my tools are limited.... I'm using textpad for code and the only thing I have to troubleshoot is the browser. The isset command under checkLogin references a session name called "loggedin" IN that case, I would have to set my session to generate a session titled "loggedin" // Starts the Session session_start(); // Gives the session a name????? $_SESSION['login']="loggedin";
  14. so after the post, we need to do a session_start(loggedin)
  15. But this should be referenced in a page other than the login_class.php page? So far the function processForm() does the following: -echo's "form processing.." -verifies the username and password using $this to reference the username/password variable function processForm() { echo "form processing..."; } { if($_POST['username']==$this->username && $_POST['password']==$this->password) } Now what to do with it afterward, I haven't used session variables. However, I don't think the form process function is complete.
×
×
  • Create New...