master82 Posted June 15, 2006 Share Posted June 15, 2006 This is the script I have at the top of my pages as an include, when I run the pages the page loads up as a blank white page, however, when I remove the include it loads up correctly. So can somebody please take a look at my code and see where I'm going wrong[code]<?phpsession_start();include("dbconnect.php");$expire = $_SESSION['expire'];$sql = "select userid from users_tbl where userid = '".$_SESSION['userid']."' AND username = '".$_SESSION['username']."'";$result = mysql_query($sql,$conn) or die(("No matches");if (mysql_num_rows($result) == 1) {$now = time();if ($now <= $expire) {unset($_SESSION['expire']);$newexpire = time()+900;$_SESSION['expire'] = $newexpire;}else{session_destroy();header("Location: login.php");}}else{session_destroy();header("Location: login.php");}?>[/code](it might also help if I mention that the server has upgraded from php4 to php5, so will this have any effect on this?) Quote Link to comment https://forums.phpfreaks.com/topic/12054-include-not-working/ Share on other sites More sharing options...
ToonMariner Posted June 15, 2006 Share Posted June 15, 2006 You will have to post the code in the dbconnect file (make sure you change all the connection details mind you!)There is a significant difference between 4 and 5 mainly in the implementation of classes so if there is any oop code in there that could be you problem. Quote Link to comment https://forums.phpfreaks.com/topic/12054-include-not-working/#findComment-45833 Share on other sites More sharing options...
master82 Posted June 15, 2006 Author Share Posted June 15, 2006 dbconnect.php[code]<?php$conn = mysql_connect("localhost", "username", "password") or die("Cant connect to the database");mysql_select_db("database",$conn);?>[/code]Now that I think of it, should I be using localhost or should I be using the IP address of my site followed by htdocs ("xxx.xxx.xxx.xxx/htdocs")? Quote Link to comment https://forums.phpfreaks.com/topic/12054-include-not-working/#findComment-45835 Share on other sites More sharing options...
wildteen88 Posted June 15, 2006 Share Posted June 15, 2006 No, you only use localhost if it your mysql server is setup on the same server your site is. If your mysql server is not then you'll need to use the mysql servers IP address instead, but 90% localhost works.Also if you are including dbconnect.php make sure you have the correct path to the file, otherwise PHP will not be able to locate your file, which is most probably the case if you you are getting a blank page. dbconnect.php should be in the same directory as the file you are inlcuding it in unless you state the path to the file.Check your servers error log which may have an error which states that PHP cannot find dbconnect.php. The code in dbconnect.php is fine and I have a feeling that PHP is having trouble including it. Quote Link to comment https://forums.phpfreaks.com/topic/12054-include-not-working/#findComment-45846 Share on other sites More sharing options...
master82 Posted June 15, 2006 Author Share Posted June 15, 2006 Its not the connect file - After playing around abit I figured out that the thing is case sensitive when it comes to table names!When I run the script it works - well it redirects me to the login page lol(so can somebody suggest a better way of writing the script because it seems I did it wrong! [although it did seem to work on my local machine?!?!])(to make it understandable, the session has 3 values, userid, username and expire. I need to check the id and username match in the database, if they do the expire is updated. If not then redirected to login. But then if expire has expired, redirect also) Quote Link to comment https://forums.phpfreaks.com/topic/12054-include-not-working/#findComment-45853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.