3 problems, Site down and mail(), $_SESSION not working.

Status
Not open for further replies.

charlies

New Member
Messages
39
Reaction score
0
Points
0
Hi all, I just registered a domain (www.charliesomerville.com) and 5 minutes later the registration went through and the DNS records seemed to propagate as I could access my site.
Now though (about 10 minutes after charliesomerville.com first went active), whenever I try and access my site, FF comes up with an error:
The connection was reset.
The connection to the server was reset while the page was loading.
I am using the Ad-Free plan.
Can anyone shine some light on this issue?
Have the servers been rebooted or are they down?
Thanks.

EDIT: The site works now, disregard this issue. But the mail() issue is still happening though!

Second issue:
A few days ago, I upgraded my PHP to Intermediate to use the mail() function.
The mail function has never worked on my site, and in Account Settings, it tells me that the exim service is down.
I read a post about a bug in the Account Settings having a bug that always shows exim as down due to the script not authenticating, but this does not explain why mail is not working.
Do I need to use PEAR mail or some other library to send emails since mail() does not support authentication?
I assumed it would work since it was one of the prominent features of Intermediate PHP.

Third issue:
I am trying to use $_SESSION to keep login data (encypted, of course) across page views, but it isn't working.
Each page has session_start() like it should but the session data is not staying across page views and when I log in, it still says I am logged out.
Any answers?
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
There was a problem with the mail queue on the server you are on, I just fixed it though. I believe that was the problem with mail() on your site.

I set up a script to test quickly (public_html/testEmail.php). I just ran it and I received the email, so it looks like it is working now.

How are you starting your sessions?

I set up two more quick tests on your account (/public_html/testSession1.php and /public_html/testSession2/php).

The first script sets a session variable and print_r()'s the session super globe variable. It's showing that the session variable is being set successfully. The second script also print_r()'s $_SESSION. That one is showing the same results as the first script, that the session variable is set correctly and can be read.

Can you show us an example of where you're having a problem? Sessions appear to be working for me correctly.
 

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
I might be incorrect, i don't know what he has in his code, but do you have super globals? I think you need to use some super globals and add a session start thing on every page (I think) Or something like that, i read about it somewhere that you need to have some sort of session code on each page so it checks if the user has a current session or something.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
I might be incorrect, i don't know what he has in his code, but do you have super globals? I think you need to use some super globals and add a session start thing on every page (I think) Or something like that, i read about it somewhere that you need to have some sort of session code on each page so it checks if the user has a current session or something.

I'm not sure what you are asking..

PHP has what are called Superglobals. That is what I was referring to with $_SESSION. $_SESSION is a superglobe variable, as well as $_POST, $_GET, $_SERVER, $_ENV, etc etc.

http://us.php.net/manual/en/language.variables.predefined.php
 

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
Ahh, yeah sorry...i didn't know what those $_GET and $_POST were called... :p Yeah, you definately need to add them, Sorry xD I'm a php newbie just thought i'd try to help.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
They've been a major part of PHP since version 4.1.0, so.. They're there.. and have been.
 

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
I know this is a bit off topic, but i quite understand HTML, and would like to get into PHP more, is there any good tutorials, ive looked at a few on the net, but i get results that aren't really helpful.
 

charlies

New Member
Messages
39
Reaction score
0
Points
0
Thanks for doing that Bryon, You wanted me to post some of my script so you could see what was going on so here we go:

accounts_api.php
(login function & db interface function)
PHP:
function api_db_connect($query) {
    $db_host = "localhost";
    $db_user = "*****";
    $db_pass = "*****";
    $db_name = "chasom_csc";
    mysql_connect($db_host,$db_user,$db_pass);
    @mysql_select_db($db_name) or die("Can't connect to database. Please try again in a few minutes.");
    $result=mysql_query($query);
    mysql_close();
    return $result;
}
function api_login($username,$password) {
    if(preg_match("/^[a-zA-Z0-9_]+$/",$username) and $password) {
        $result = api_db_connect("SELECT * FROM users WHERE user='$username'");
        if(mysql_num_rows($result)) {
            $cryptpass = mysql_result($result,0,"pass");
            if(md5($password) == $cryptpass) {
                return true;
                api_logout();
                session_start();
                $_SESSION['username'] = $username;
                $_SESSION['password'] = $cryptpass;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}
The login function works fine, except i'm not too sure about the session code in some of my functions

login_v.php
PHP:
<?php
require("accounts_api.php");
session_start();
if(api_login($_POST['user'],$_POST['password'])) {
require("header.php");
$u = mysql_escape_string($_POST['user']);
$result = api_db_connect("SELECT * FROM users WHERE user='$u'");
$v = mysql_result($result,0,"validation");
if($v > 10000000) {
    api_logout();
?>
<center>
<p>
Your email address has not been verified yet.
You must verify your account in order to login.
</p>
<p>
<a href="index.php">Back</a>
</p>
</center>
<?
} else {
?>
<center>
<p>
Welcome back, <?=$_POST['user'];?>.
</p>
<p>
<a href="index.php">Back</a>
</p>
</center>
<?
}
require("footer.php");
} else {
    header("Location: login.php?incorrect=1");
}
?>
When I login with my username, it says: 'Welcome back, charlie.', but the userbar (part of header.php) that normally displays user details and links when logged in, and 'Click to login.' when not, just says 'Click to login.'
I think the problem lies in header.php

header.php
PHP:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CS Computers</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="userbar.css" rel="stylesheet" type="text/css" />
</head>


<body>
<div id="userbar">
<?
if($_SESSION['username']) {
    require("includes/accounts_api.php");
    if(api_validate()) {
?>
<img src="http://forums.x10hosting.com/images/user.png" id="msg_loggedin_img"/>
<div id="msg_loggedin_part1">
&nbsp;<?=$_SESSION['username'];?> - <?=api_getvar("points");?> points
</div>
<div id="msg_loggedin_part2">
<a href="account.php">My Account</a> | <a href="account.php?action=products">My Products</a> | <a href="members.php">Members Area</a> | <a href="help.php">Help & Support</a> | <a href="logout.php">Logout</a>&nbsp;
</div>
<?
    } else {
?>
<div id="msg_loggedout" onClick="location.href='login.php'">Click to login (validate = false)</div>
<?
    }
} else {
?>
<div id="msg_loggedout" onClick="location.href='login.php'">Click to login (no session)</div>
<?
}
?>
</div>
<table cellpadding="0" cellspacing="0" border="0" id="layout_tbl">
<tr>
    <td id="header" colspan="7">&nbsp;
        
    </td>
</tr>

<tr id="menu">
    <td class="menumargin">&nbsp;
    
    </td>

    <td class="menuitem" onClick="location.href='index.php'">
        Home
    </td>
    <td class="menuitem" onClick="location.href='catalog.php?action=software'">
        Software
    </td>
    <td class="menuitem" onClick="location.href='catalog.php?action=systems'">
        Systems
    </td>
    <td class="menuitem" onClick="location.href='contact.php'">
        Contact
    </td>
    <td class="menuitem" onClick="location.href='login.php'">
        Login
    </td>

    <td class="menumargin">&nbsp;
            
    </td>
</tr>

<tr>
    <td id="content" colspan="7">
I added debugging info earlier to each of the 'Click to login.' messages and it always tells me that it was showing because of no session.

EDIT: Bryon, if you need more, you are always welcome to view the files in my account
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Hmmm. I'm not really sure what is going on. I just spent an hour trying to go through the code and see what is not working. For some reason, you're two setcookie() calls once a user is successfully logged in are "setting cookies" that are not actually being "set." I'm not sure why that is happening, it must be something within the code. Both setcookie() function calls are returning true.

http://charliesomerville.com/cookieTest.php

That test sets a cookie which is able to be read on http://charliesomerville.com/cookieTest2.php, and remains there for any further refreshes until the end of the session.

I know now that both cookies and sessions are working correctly. I'm not sure why your scripts are not, I've tried to determine the cause but failed to do so. I do not have a lot of time to spend continuing to try though, sorry.
 

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
I have a very very basic login/register script if you wish to have it, i could email it to you or something.. just let me know..
 
Status
Not open for further replies.
Top