Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

Include not working

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?)

Share this post


Link to post
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.

Share this post


Link to post
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")?

Share this post


Link to post
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.

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

×

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.