budder Posted April 12, 2010 Share Posted April 12, 2010 My php host site is runing php 4.4.4 and that is a problem because when i run the script in wamp on localhost there is no problem. But When I got it on the php host, problems popped up. I know there is alot of new function in php 5.02 > but i don't think that is the problem, or is it? <?php functions.inc.php function redirect($page) { header('Location: ' . $page); exit(); } function check_login_status() { // If $_SESSION['logged_in'] is set, return the status if (isset($_SESSION['logged_in'])) { return $_SESSION['logged_in']; } return false; } ?> login.inc.php <?php require_once('config.inc.php'); require_once('functions.inc.php'); session_start(); // Check if user is already logged in if ($_SESSION['logged_in'] == true) { // If user is already logged in, redirect to main page redirect('../index.php'); } else { // Make sure that user submitted a username/password and username only consists of alphanumeric chars if ( (!isset($_POST['username'])) || (!isset($_POST['password'])) OR (!ctype_alnum($_POST['username'])) ) { redirect('../login.php'); } // Connect to database $mysqli = @new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); // Check connection if (mysqli_connect_errno()) { printf("Unable to connect to database: %s", mysqli_connect_error()); exit(); } // Escape any unsafe characters before querying database $username = $mysqli->real_escape_string($_POST['username']); $password = $mysqli->real_escape_string($_POST['password']); // Construct SQL statement for query & execute $sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . md5($password) . "'"; $result = $mysqli->query($sql); // If one row is returned, username and password are valid if (is_object($result) && $result->num_rows == 1) { // Set session variable for login status to true $_SESSION['logged_in'] = true; redirect('../index.php'); } else { // If number of rows returned is not one, redirect back to login screen redirect('../login.php'); } } ?> First there where no errors when i tried loggin in but after hitting enter it just the blank login.inc.php I get. Then I tried an easy error handling: function customError($errno, $errstr) { echo "<b>Error:</b> [$errno] $errstr"; } set_error_handler("customError"); at the top of my login.inc.php (After requiere and session_start() Now i got something. There is and undefined index: logged_in. Aha! So scripts is making an error because i have'nt defined the session and therefore it is returning NULL session. Then i tried session_is_registred(logged_in) strangly the error messeage disapered but I still get the blank login.inc.php and I am getting pretty blank. So if there is anyone who can help me out with this problem i will be very greatful. //Budder Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/ Share on other sites More sharing options...
TeddyKiller Posted April 12, 2010 Share Posted April 12, 2010 Don't reverse your back to PHP 4.x.x just for the host. Because when they do upgrade, you'll have problems again. Contact your webhost about upgrading to PHP 5.x.x or if they refuse to do this, or the time consuming of it is too long and your running out of bread (patience) then .. perhaps get a new webhost and ask them to transfer the files over from this host. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040247 Share on other sites More sharing options...
Pikachu2000 Posted April 12, 2010 Share Posted April 12, 2010 Don't downgrade your code to conform to a hosting company that uses out of date software. Change hosting companies. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040249 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2010 Share Posted April 12, 2010 The ONLY thing your code is doing that is php5 specific is using the mysqli extension (which would account for the blank pages because you would be getting a fatal runtime error.) The end of life of php4 was over two years ago. Your web host should have provided a way of selecting php5, either through a control panel menu item or through adding a command in a .htaccess file. Spend your time updating the account to php5, not wasting your time fixing non-problems in the code. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040257 Share on other sites More sharing options...
budder Posted April 12, 2010 Author Share Posted April 12, 2010 Yeah your right guys, there is no reason to degrade my php script although I have'nt used any php5 :b Im not the hostmaster og the site I only help with some coding. But i would certainly tell the hostmaster to change host. So to fix the blank page I should use mysql_query instead? Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040275 Share on other sites More sharing options...
oni-kun Posted April 12, 2010 Share Posted April 12, 2010 Yeah your right guys, there is no reason to degrade my php script although I have'nt used any php5 :b Im not the hostmaster og the site I only help with some coding. But i would certainly tell the hostmaster to change host. So to fix the blank page I should use mysql_query instead? Yes, You should look at the mysql_query format. All in all it doesn't matter, Performance wise it's in a fractional margin. You should turn error reporting to E_ALL during development with display_errors on, It should provide useful information instead of blank screens as well. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040276 Share on other sites More sharing options...
budder Posted April 12, 2010 Author Share Posted April 12, 2010 Thanks. Great answers. I will try it out tomorrow. And thanks for the blog link (mysql vs. mysqli) Does php4 support md5 og sha1? Or is it password(); ? Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040288 Share on other sites More sharing options...
oni-kun Posted April 12, 2010 Share Posted April 12, 2010 Thanks. Great answers. I will try it out tomorrow. And thanks for the blog link (mysql vs. mysqli) Does php4 support md5 og sha1? Or is it password(); ? It supports md5, sha1 and crypt, Although crypt()'s underline coding may have changed through versions, you can check the documentation. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040291 Share on other sites More sharing options...
budder Posted April 13, 2010 Author Share Posted April 13, 2010 Hey guys. Can you help me one more time? Got this syntax error, unexpected $end in login.inc.php on line 46. I have tried degrade my script (I have to i know it's stupid) but I am missing something? <?php // Include required MySQL configuration file and functions require_once('config.inc.php'); require_once('functions.inc.php'); // Start session function customError($errno, $errstr) { echo "<b>Error:</b> [$errno] $errstr"; } if ($_SESSION['logged_in'] == true) { // If user is already logged in, redirect to main page redirect('../index.php'); } else { // Make sure that user submitted a username/password and username only consists of alphanumeric chars if ( (!isset($_POST['username'])) || (!isset($_POST['password'])) OR (!ctype_alnum($_POST['username'])) ) { redirect('../login.php'); } $mysqli = mysql_connect("$DB_HOSTNAME", "$DB_USERNAME", "$DB_PASSWORD"); mysql_select_db("DB_DATABASE", $mysqli) or die("Can not connect"); // Check connection if (mysql_error()) { printf("Unable to connect to database: %s", mysql_error()); exit(); } // Escape any unsafe characters before querying database $username = $_POST['username']; $password = $_POST['password']; // Construct SQL statement for query & execute $sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "'"; $result = mysql_query($sql,$db); // If one row is returned, username and password are valid if (is_object($result) && mysql_num_rows == 1) { // Set session variable for login status to true $_SESSION['logged_in'] = true; redirect('../index.php'); } else { // If number of rows returned is not one, redirect back to login screen redirect('../login.php'); } ?> Remember, its PHP4 :b Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040754 Share on other sites More sharing options...
Mchl Posted April 13, 2010 Share Posted April 13, 2010 This else if ($_SESSION['logged_in'] == true) { // If user is already logged in, redirect to main page redirect('../index.php'); } else { has no closing bracket } Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040755 Share on other sites More sharing options...
budder Posted April 13, 2010 Author Share Posted April 13, 2010 Thanks for the quick response, I try it out. Can you recommend a good php editor that can eliminate problems like that another time? Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040757 Share on other sites More sharing options...
oni-kun Posted April 13, 2010 Share Posted April 13, 2010 Thanks for the quick response, I try it out. Can you recommend a good php editor that can eliminate problems like that another time? http://www.phpfreaks.com/forums/index.php/topic,277416.0.html If you're on Windows, Netbeans or Notepad++ supports syntax/brace match highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040758 Share on other sites More sharing options...
budder Posted April 13, 2010 Author Share Posted April 13, 2010 doesn't Dreamweaver support this function? Thanks anyway (: Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040759 Share on other sites More sharing options...
oni-kun Posted April 13, 2010 Share Posted April 13, 2010 doesn't Dreamweaver support this function? Thanks anyway (: Yes, But Dreamweaver is bloatware for most developers who don't need all the pampered features. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040764 Share on other sites More sharing options...
TeddyKiller Posted April 13, 2010 Share Posted April 13, 2010 However.. notepad++ when you go onto a new line, it doesn't indent it for you (like when you have an if statement) Dreamweaver does. Sometimes this helps you work out where your going wrong 'curly brace' wise. example. //This is correct if { if { if { 'statement' } } } //This isn't correct if { if { if { 'statement' } } //This, is confusing to work out the problem. (notepad++ style, and no problem in this example) if { if { if { 'statement' } } } Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040765 Share on other sites More sharing options...
Mchl Posted April 13, 2010 Share Posted April 13, 2010 There's nothing stopping you from adding your own indents. Actually some people prefer to do it themselves. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040768 Share on other sites More sharing options...
oni-kun Posted April 13, 2010 Share Posted April 13, 2010 Actually Notepad++ does follow the current indentation. The indentation you gave as an example, is... Should we say, superfluous. I don't think you need 300 whitespace characters per page of code for help. Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040770 Share on other sites More sharing options...
budder Posted April 13, 2010 Author Share Posted April 13, 2010 Alright guys I got my mysqli statements to mysql. But something doesn't work. When trying to log in the script just send my back to the login. Then I checked the data in the sql database. I got two users: test1 and test2 Test1 got md5 crypt and test2 doesn't. (I know I got my md5($password) in the script ) But i tried to chance the response so it didn't crypt the md5. But neither way working its just sending me back to basic (login) have a look... again. <?php // Include required MySQL configuration file and functions require_once('config.inc.php'); require_once('functions.inc.php'); // Start session if ($_SESSION['logged_in'] == true) { // If user is already logged in, redirect to main page redirect('../index.php'); } else { // Make sure that user submitted a username/password and username only consists of alphanumeric chars if ( (!isset($_POST['username'])) || (!isset($_POST['password'])) OR (!ctype_alnum($_POST['username'])) ) { redirect('../login.php'); } $mysqli = mysql_connect("$dbHost", "$dbUser", "$dbPass"); mysql_select_db($dbDatabase, $mysqli) or die("Can not connect"); // Check connection if (mysql_error()) { printf("Unable to connect to database: %s", mysql_error()); exit(); } // Escape any unsafe characters before querying database. PHP4 doesn't $username = $_POST['username']; $password = $_POST['password']; // Construct SQL statement for query & execute Tried deleting md5(); to check test2 user, but nothing worked. $result=mysql_query("select * from users where username='" . $username. "' AND password='" . md5($password) . "'", $mysqli); // If one row is returned, username and password are valid if (is_object($result) && mysql_num_rows == 1) { // Set session variable for login status to true $_SESSION['logged_in'] = true; redirect('../index.php'); } else { // If number of rows returned is not one, redirect back to login screen echo $result; } } ?> Tried deleting md5(); to check test2 user, but nothing worked. EDIT: tried to echo the $result and it gives me: Resource id #5 Shouldn't it be showing my sql-statement? Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040801 Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2010 Share Posted April 13, 2010 You can't echo $result to echo the data from the table. You need to pass the result to another function such as mysql_fetch_assoc() to use it. You can see a little more if you use var_dump($result). Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040876 Share on other sites More sharing options...
ChemicalBliss Posted April 13, 2010 Share Posted April 13, 2010 However.. notepad++ when you go onto a new line, it doesn't indent it for you (like when you have an if statement) Dreamweaver does. OMG no offense but you should be shot . Notepad++ has one of the best line matching algorithms i know of. It follows your cursor up and down, indents code exactly how you indent it etc, nothing wrong with it at all. -CB- (Dreamwaver is pointless, get something free, You will learn 10x faster with plain text editors than with WYSIWYGS like dreamweaver) Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040913 Share on other sites More sharing options...
TeddyKiller Posted April 13, 2010 Share Posted April 13, 2010 OMG no offense but you should be shot . Shoot me and I shoot you twice. Yeah, notepad++ has the best line matching, but it doesn't indent for you Actually I was doing some work using notepad++ I feel it is more of a developers tool than what dreamweaver is. Just annoying with the indenting xD Quote Link to comment https://forums.phpfreaks.com/topic/198257-php4-host-but-php5-code-dont-know-what-to-do/#findComment-1040974 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.