
webmaster1
Members-
Posts
607 -
Joined
-
Last visited
Never
Everything posted by webmaster1
-
Difficulty including database connect info...
webmaster1 replied to webmaster1's topic in PHP Coding Help
Understood. It would be handy if the manual positioned the notice of deprecation at the start of the page. It doesn't seem to recommend the correct alternative either. Never mind me, just nagging. -
Difficulty including database connect info...
webmaster1 replied to webmaster1's topic in PHP Coding Help
Understood. Apologies for the cloak and dagger. Here you go: index.php: <?php $loginfailstatus=$_GET['loginfailstatus']; $loginfail=$loginfailstatus; $loginfailusername=$_GET['loginfailusername']; $loginfailpassword=$_GET['loginfailpassword']; // Create value if username left blank. if (empty($loginfailusername)) { $loginfailusername="No input for this field"; } // Create value if password left blank. if (empty($loginfailpassword)) { $loginfailpassword="No input for this field"; } ?> <html> <?php // If a failed login attempt is made. if ($loginfail) { // Include database variables. include($_SERVER['DOCUMENT_ROOT']."/includes/site/dbinfo.php"); // Connect to database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define variables for query. $client="Site"; // Define current page as variable for query. // Source: http://www.webcheatsheet.com/PHP/get_current_page_url.php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $location=curPageURL(); // Define variables for query cntd. $occurrence="Illegal client login attempt"; $ipaddress=$_SERVER['REMOTE_ADDR']; // Insert into table. $query = "INSERT INTO reports VALUES ('',NOW(),'$client','$location','$occurrence','$ipaddress','$loginfailusername','$loginfailpassword')"; mysql_query($query); // Define additional variables for message. $daydate=date("l, dS"); $monthyear=date("F, Y"); $time=date("H:i:s a"); // THIS QUERY DOESN'T QUITE WORK YET - CURRENTLY LEARNING HOW TO ADD FETCH RESULTS $query2 = "SELECT COUNT(id) AS cumulativeloginfails FROM reports"; $cumulativeloginfails = mysql_query($query2); echo $cumulativeloginfails; // Echo message. echo " <p>You have not entered a valid username and/or password. Successive failed attempts will result in a ban that will prevent your access to this website. Please verify your credentials before attempting to enter them again. Contact the site administrator if you experience further difficulty.</p> <p><a href='/index.php'>Go back to client login form.</a></p> <p><a href='/contact.php'>Contact the site administrator.</a></p> <p>Occurrence: ".$occurrence.".</p> <p>Attempted username: ".$loginfailusername.".</p> <p>Attempted password: ".$loginfailpassword.".</p> <p>IP address retained: ".$ipaddress."</p> <p>Cumulative illegal attempts from this IP Address:</p> <p>Date logged: ".$daydate." of ".$monthyear.".</p> <p>Time logged: ".$time."</p> "; } else { ?> <form name="form1" method="post" action="includes/site/login-check.php"> <ol> <li>Username: <input name="loginusername" type="text" id="loginusername"></li> <li>Password: <input name="loginpassword" type="password" id="loginpassword"></li> <li><input type="submit" name="login" value="Login"></li> </ol> </form> <?php } ?> </html> login-success.php: <?php session_start(); if(!session_is_registered(myusername)){ // Redirects when the following url is directly accessed: header("location:/index.php"); } ?> <html> <body> Login Successful </body> </html> Error messages: -
Difficulty including database connect info...
webmaster1 replied to webmaster1's topic in PHP Coding Help
Why doesn't dbinfo.php need it? I thought the only significant difference between the require() and include() functions was how they handled errors. -
Difficulty including database connect info...
webmaster1 replied to webmaster1's topic in PHP Coding Help
The tutorial seems to have gone about it that way. -
Difficulty including database connect info...
webmaster1 replied to webmaster1's topic in PHP Coding Help
I understand what you've explained but cannot fathom why the error is exclusive to using the include function. In theory, the same problem should persist when I don't use the include function. I have a basic username and password form that posts to check.php which in turn runs a database check on the input and thereafter redirected. I used the following as my basis http://www.phpeasystep.com/phptu/6.html Here's my actual code for check.php: <?php $host="x"; // Host name $username="x"; // Mysql username $password="x"; // Mysql password $db_name="x"; // Database name $tbl_name="x"; // Table name // Include database variables. //include($_SERVER['DOCUMENT_ROOT']."/somefolder/dbinfo.php"); // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $loginusername=$_POST['loginusername']; $loginpassword=$_POST['loginpassword']; // To protect MySQL injection (more detail about MySQL injection) $loginusername = stripslashes($loginusername); $loginpassword = stripslashes($loginpassword); $loginusername = mysql_real_escape_string($loginusername); $loginpassword = mysql_real_escape_string($loginpassword); $sql="SELECT * FROM $tbl_name WHERE username='$loginusername' and password='$loginpassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $loginusername and $loginpassword, table row must be 1 row if($count==1){ // Register $loginusername, $loginpassword and redirect to file "login_success.php" session_register("loginusername"); session_register("loginpassword"); header("location:login-success.php"); } else { header("location:/index.php?loginfailstatus=TRUE&loginfailusername=$loginusername&loginfailpassword=$loginpassword"); } ?> You'll notice I tweaked the header link for the a failed login by passing two variables through the url. Nothing major. The page containing my form uses an insert query (stores ip for failed login) and that's about the extent of it. -
Difficulty including database connect info...
webmaster1 replied to webmaster1's topic in PHP Coding Help
But the database connection and the query works fine when I don't use the include. Should that not indicate that the query is not the issue? Everything is hunky-dory until I replace my connection variables with the include function. -
I'm using the following to define my connection details and it works fine: <?php $host="x"; // Host name $username="x"; // Mysql username $password="x"; // Mysql password $db_name="x"; // Database name $tbl_name="x"; // Table name ?> I've tried to replace this using the include function: include($_SERVER['DOCUMENT_ROOT']."/somefolder/dbinfo.php"); For some reason I get the following errors: How is that I'm overlooking the include function?
-
Thanks!
-
That's exactly what I was trying to achieve, much thanks. My JavaScript skills are reserved mainly to editing large chucks of copied and pasted unoriginal code. I was trying to figure out how to do this on W3schools but just couldn't piece it together. Cheers!
-
I want to display and dynamically interchange the text within a <div> when the mouse cursor hovers over either one of four images. For example, image1, image2, image3, and image4 could prompt start, previous, next and end respectivly. Can anyone assist me in triggering the text to be displayed and interchanged as described? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Show Text on Image Hover</title> </head> <body> <div id="showtext"> <?php echo""; ?> </div> <img src="images/image1.jpg" width="25" height="25" alt="image1" name="image1" id="image1" > <img src="images/image2.jpg" width="25" height="25" alt="image2" name="image2" id="image2" > <img src="images/image3.jpg" width="25" height="25" alt="image3" name="image3" id="image3" > <img src="images/image4.jpg" width="25" height="25" alt="image4" name="image4" id="image4" > </body>
-
In contrast to building a site that integrates SMF and Wordpress, what are your thoughts on using NING Networks? Flippant opinions welcome.
-
I want to link to the latest browser versions for download by IE, FF, Safari, Opera and Chrome. Does anyone know of a neat way of doing this or do I simply paste the link to their download pages? The link for Chrome is fairly long, as if it's curtailed to me specifically (e.g. geographical location): Does this look like the correct url or is there a more direct link for downloading browsers?
-
Cheers!
-
I want to echo a message if my document is being viewed in IE6. I've come across the following 2 ways: <!--[if IE 6]> <p>IE6 detected!</p> <![endif]--> or <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') !== FALSE) { echo 'IE6 detected!'; } /* else { echo 'IE6 not detected!'; } */ ?> Which approach do you reccomend?
-
What do you think of the new look of these forums?
webmaster1 replied to smerny's topic in PHPFreaks.com Website Feedback
How about custom board icons? http://custom.simplemachines.org/mods/index.php?mod=511 -
Advise on how to go about expandable content with cookies.
webmaster1 replied to webmaster1's topic in PHP Coding Help
Thanks for the feedback, Hussam. -
I want to implement expandable content on my site that uses cookies to determine whether the content should remain expanded or contracted. Look to the top right of this page for an exact example of what I'm trying to achieve. Question 1: Is it possible to use cookies to remember expansion/contraction and/or is this something I can apply to visitors based on their IP address without them being members of my site? Question 2: How should I plan this out? Is javascript (client) or php (server) the way to go or will I be using both?
-
Need help with my forums (made from scratch)
webmaster1 replied to DarrenReeder's topic in PHP Coding Help
I recommend using SMF. It's free, powerful, compliant and php-based. This forum, phpfreaks, is an SMF forum. View here: http://www.simplemachines.org/ There's a decent amount of work involved in customizing the forum both in terms of it's appearance and functionality but if you want to use it 'as is' or use another designers theme then even a novice can install it and have it up and running in less than 20 minutes. If you really, really, really want to build a forum from scratch then the problem you're currently having is with CSS. I took a peak at your source code and it looks like you're designing your forum in a fairly out of fashion manner. There is no separation between the design and content of your site which is most likely why it's messing up in different browsers. e.g. you're applying background images directly to your body element and wrapping font tags around the content of your list items in the sidebar section. With CSS, only your content dwells in your html/php document and everything that effects how the content appears (background images, font colors, page width, links etc.) is coded in an external document known as a style sheet. It's not at all complicated if you have a little time to school yourself with hundreds of free tutorials online. In conclusion, if you want a powerful and free solution for a forum, use SMF. If you're interested in building it from scratch then spend an hour or two learning how to use CSS. You'll be shocked how much your caliber as a coder will evolve if you dedicate a minimum amount of time towards learning CSS and the contemporary standards of the internet. Start here: http://www.w3schools.com/css/css_intro.asp EDIT: I'd personally avoid the use of frames. After reviewing your site, it looks like you can achieve the exact same thing using a CSS layout (http://www.code-sucks.com/css%20layouts/fixed-width-css-layouts/) and the PHP inlcude function (http://www.tizag.com/phpT/include.php). -
Yep, go with Haku on this one. I never thought about the longevity of hacks which is fairly important.
-
This except should solve your issue: * html Source: http://www.edgeofmyseat.com/blog/developing-css-for-ie6-and-7
-
Should I still cater for IE6 or is it time to move on?
webmaster1 replied to webmaster1's topic in CSS Help
Cheers, haku. I'll most likely go with the conditional statement on link element. It's a new site so I can't base it on any stats other than national browser shares. For SMF, I might see if I can just swap out the theme completely rather than just the style sheet. -
If you can't get min-height to work on an older IE version then hacks exists: http://perishablepress.com/press/2007/01/16/maximum-and-minimum-height-and-width-in-internet-explorer/ http://www.dustindiaz.com/min-height-fast-hack/ http://snipplr.com/view/62/minheight-for-ie-and-all-other-browsers/
-
I see what you mean. I've tested this and it the CSS renders the same in Chrome, FF and IE6: <div id="container" style="background-color:#CCC; min-height:10px;"> <div id="middle" > hello <div id="middleleft"> egg <br><br><br><br><br> </div> bye </div> Notice that all I done was specified an minimum height. Once the content of your div goes beyond 10px the grey background will automatically 'stretch'. If anything IE6 was behaving problematically rather than any other browser type. Nine times out of ten it'll be IE6.
-
What version of IE are you referring to? Use this for setting the minimum height: http://www.w3schools.com/CSS/pr_dim_min-height.asp