Jump to content

crouzilles

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

crouzilles's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Damn, I am a fool. used == instead of = Don't why I did that. Sorry about that and thank you for your time.
  2. The domain does not change, the path remains the same at all time. These two files are on the server root as all the other files for that matter. So still at a loss to explain why this is happening. If anyone has anymore ideas, please let me know. Is there something in php.ini that could be set wrong? Thank you
  3. Hi all, I have a problem with a script which gets called from a link in an email. This script confirms new members to the site. In this script called confirm.php, which is pasted below, I set a session variable called $_SESSION['feedback'] or one called $_SESSION['success']. Once the confirm.php script has finished doing its stuff, it redirects to index.php. index.php uses the feedback or success session variables to determine what to output, unfortunately, it seems the session variables do not exist. I have got session_start(); at the top of index.php as well as in confirm.php, I am at a loss as to what could be wrong. I have spent hours reading forums and browsing, to no avail. <?php session_start(); # Source utility functions require_once("func/utils.php"); # Source db functionality require_once("func/db.php"); function user_conf_exists($email, $uid) { global $logger, $DB; $logger->log("-->confirm.php--user_conf_exists: ".$email." ".$uid,PEAR_LOG_INFO); $sql = "select username from tcustomer where email = $1 and uid = $2 and confirmed = 'N'"; $result = pg_query_params($DB, $sql, array($email, $uid)); if (!$result) { $logger->log("-->confirm.php--user_conf_exists - ".pg_last_error(), PEAR_LOG_ERR); $logger->log("-->confirm.php--user_conf_exists - Got unknown result from the DB", PEAR_LOG_WARNING); return -1; } else { # ok, we have successfuly run the query, do we have a row? $logger->log("-->confirm.php - Got result from the DB", PEAR_LOG_INFO); $rows = pg_num_rows($result); if($rows == 1) { # ok, we have found the user $logger->log("-->confirm.php--user_conf_exists - Result has 1 row, return 1", PEAR_LOG_INFO); while ($row = pg_fetch_object($result)) { $_SESSION['user'] = $row->username; } return 1; } else { $logger->log("-->confirm.php--user_conf_exists -Not exactly 1 row returned", PEAR_LOG_INFO); return 0; } } } function update_confirmed($conf, $email, $uid) { global $logger, $DB; $logger->log("-->confirm.php--update_confirmed: ".$conf,PEAR_LOG_INFO); $sql = "update tcustomer set confirmed = $1 where email = $2 and uid = $3"; $result = pg_query_params($DB, $sql, array($conf, $email, $uid)); if (!$result) { $logger->log("-->confirm.php--update_confirmed - ".pg_last_error(), PEAR_LOG_ERR); $logger->log("-->confirm.php--update_confirmed - Got unknown result from the DB", PEAR_LOG_WARNING); return -1; } else { # ok, we have successfuly run the query, do we have a row? $logger->log("-->confirm.php--update_confirmed - Got result from the DB", PEAR_LOG_INFO); $rows = pg_affected_rows($result); if($rows == 1) { # ok, we have found the user $logger->log("-->confirm.php--update_confirmed - Result has 1 row, return 1", PEAR_LOG_INFO); return 1; } else { $logger->log("-->confirm.php--update_confirmed -Not exactly 1 row returned", PEAR_LOG_INFO); return 0; } } } if ($_SERVER['REQUEST_METHOD'] == 'GET') { $logger->log("-->confirm.php- Handling GET request...", PEAR_LOG_INFO); $email = safe($_GET['email']); $uid = safe($_GET['uid']); $user_exists = user_conf_exists($email, $uid); if ($user_exists == -1) { $_SESSION["feedback"] == "db_unknown_result"; db_close(); header("Location: index.php"); return; } if ($user_exists == 0) { $_SESSION["feedback"] == "unknown_conf_user"; db_close(); header("Location: index.php"); return; } $conf = update_confirmed("Y", $email, $uid); if ($conf == -1) { unset($_SESSION['user']); $_SESSION["feedback"] == "db_unknown_result"; db_close(); header("Location: index.php"); return; } if ($conf == 0) { unset($_SESSION['user']); $_SESSION["feedback"] == "conf_user_no_update"; db_close(); header("Location: index.php"); return; } $_SESSION["success"] == "conf_success"; } else { $_SESSION["feedback"] == "unknown_conf_args"; } header("Location: index.php"); ?> I have tried to put the full url instead of just index.php, to no avail. Thank you
  4. Thank you for the help, very much appreciated.
  5. This is the script so far. html below body tag not included. <?php # Start the session session_start(); # Source utility functions require_once("utils.php"); # Source db functionality require_once("db.php"); $p_username = ""; $p_email = ""; $p_fname = ""; $p_lname = ""; $p_country = ""; function username_exists($uname) { global $logger, $DB; $logger->log("-->utils.php--username_exists: ".$uname,PEAR_LOG_INFO); $sql = "select username from tcustomer where username = $1"; $result = pg_query_params($DB, $sql, array($uname)); if (!$result) { $logger->log("-->utils.php--username_exists - ".pg_last_error(), PEAR_LOG_ERR); $logger->log("-->utils.php--username_exists - Got unknown result form the DB", PEAR_LOG_WARNING); return -1; } else { # ok, we have successfuly run the query, do we have a row? $logger->log("-->utils.php - Got result from the DB", PEAR_LOG_INFO); $rows = pg_num_rows($result); if($rows == 1) { # ok, we have found the user in the table, this means we can't use it to register a new user $logger->log("-->utils.php - Result has 1 row, return 1", PEAR_LOG_INFO); return 1; } else { return 0; } } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { # Lets check we have values in username and password fields if (!empty($_POST['username']) && !empty($_POST['password_1']) && !empty($_POST['password_2']) && !empty($_POST['email']) && !empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['country'])) { $logger->log("-->do_signup.php - Getting registration fields", PEAR_LOG_INFO); $p_username = $_POST['username']; $p_email = $_POST['email']; $p_fname = $_POST['fname']; $p_lname = $_POST['lname']; $p_country = $_POST['country']; $pwrd_1 = md5(safe($_POST['password_1'])); $pwrd_2 = md5(safe($_POST['password_2'])); if (strcmp($pwrd_1,$pwrd_2) != 0) { $logger->log("-->do_signup.php - Password fields do not match, redirecting to signup.php", PEAR_LOG_WARNING); $_SESSION["feedback"] = "signup_password_missmatch"; exit; } $uname = safe($_POST['username']); $uname_check = username_exists($uname); db_close(); if ($uname_check == -1) { $logger->log("-->do_signup.php - Error occured while checking username exists, redirecting back to signup.php", PEAR_LOG_ERR); $_SESSION["feedback"] = "db_unknown_result"; exit; } elseif ($uname_check == 1) { $logger->log("-->do_signup.php - Username ".$uname." is already in use, redirecting back to signup.php", PEAR_LOG_INFO); $_SESSION["feedback"] = "username_taken"; exit; } $email = safe($_POST['email']); $fname = safe($_POST['fname']); $lname = safe($_POST['lname']); $country = safe($_POST['country']); $uid = generateRandomString(); $logger->log("-->do_signup.php - About to add user ".$uname." to the database", PEAR_LOG_INFO); $sql = "insert into tcustomer( username, password, email, fname, lname, country, uid) values( $1,$2,$3,$4,$5,$6,$7)"; $result = pg_query_params($DB, $sql, array($uname, $pwrd_1, $email, $fname, $lname, $country, $uid)); if(!$result) { $logger->log(pg_last_error(), PEAR_LOG_ERROR); $logger->log("-->do_signup.php - Got unknown result form the DB, redirecting to signup.php", PEAR_LOG_WARNING); $_SESSION["feedback"] = "db_unknown_result"; db_close(); exit; } else { # ok, we have successfuly run the query, do we have an affected row? $logger->log("-->do_signup.php - Got result from the DB", PEAR_LOG_INFO); $rows = pg_affected_rows($result); if($rows == 1) { # ok, we have successfuly inserted a row. $logger->log("-->do_signup.php - Result has 1 row, all is fine", PEAR_LOG_INFO); send_need_confirmation_mail($email); $_SESSION["feedback"] = "just_signed_up"; exit; } else { # we don't seem to have been able to insert anything for some strange reason $logger->log("-->do_signup.php - Result has not got 1 row, redirecting to signup.php", PEAR_LOG_WARNING); $_SESSION["feedback"] = "db_no_result"; db_close(); exit; } } } else { $logger->log("-->do_signup.php - User did not enter all required fields, redirecting to signup.php", PEAR_LOG_WARNING); $_SESSION["feedback"] = "signup_missing"; db_close(); exit; } } ?> <!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" dir="ltr" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Title goes here</title> <meta name="generator" content="EditPlus" /> <link rel="stylesheet" href="css/freshy.css" type="text/css" media="screen" /> <!--[if gte IE 7]> <link rel="stylesheet" href="css/freshy_ie7.css" type="text/css" media="screen" /> <![endif]--> <!--[if lt IE 7]> <link rel="stylesheet" href="css/freshy_ie6.css" type="text/css" media="screen" /> <![endif]--> <link rel="stylesheet" href="css/global.css" type="text/css" media="screen" /> <script type="text/javascript" src="utils.js"></script> </head> <body> Basically, anything below the body tag does not show if there is an error and I think this is because I call exit.
  6. Hello, I am pretty new to php and I have the following question. I have a page called signup.php so users on my site can sign up and become members. At the top of the page I have all my php and at the bottom all my html. When a user wants to sign up, he/she is directed to the signup.php page. I do the following to check if it is a post back if ($_SERVER['REQUEST_METHOD'] == 'POST') { If it is not a post back I don't check for request arguments and just show the html, but if it is a post back I check for request arguements as this means the user tried to sign up. My problem is as follow. When a problem occurs, for example the username already exists in the database , I set a variable which I can use in the html part to tell the user what the problem is, but what I want to do is exit the if statement as there is no need for other things to be checked. So what I did was to use the exit call, but this seems to stop the entire script and I get a blank page. Is there a way to just exit an if statement? Thank you
  7. Hello, I was wondering if PHP writes to any logs and what is the function call to write to those logs. It is handy to have logs for debugging. Also where are those logs situated, if they exist. Thank you
  8. Actually guys, Forgive me about this. I have found the problem. I call my cookie GSAdminUser, but I refer to it as GSAdminUSer. Note the uppercase 'S'? Sorry again, my mistake.
  9. Unfortunately, it still does not work. This is my file: <?php setcookie("GSAdminUser", "xbourgui:1", time()+3600, "/", "127.0.0.1", 0); ?> <html> <head> <link rel="styleSheet" href="css/main.css" type="text/css"> </head> <body class="main"> <?php if (isset($_COOKIE['GSAdminUSer'])) { echo('no cookie available'); } else { echo("cookie is now set to: {$_COOKIE['GSAdminUSer']}"); } ?> </body> </html> All I get on screen now is this: cookie is now set to: Any ideas? Thank you
  10. Hello all, I am new to PHP and to your community. I have a little programming experience in Tcl, DHTML. This is the problem I am encountering: echo("cookie is now set to: $_COOKIE['GSAdminUser']"); The line above comes back with this errror: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/username/gs_admin/test.php on line 18 If I assign the value of $_COOKIE['GSAdminUser'] to a variable and then use this variable in the echo command, all is fine and I cann see the cookie value in the page. Does anybody know what I can't use the $_COOKIE['GSAdminUser'] variable directly? Thank you
×
×
  • 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.