Jump to content

Include not working


master82

Recommended Posts

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]
<?php
session_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?)
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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")?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.