473,378 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

problems with my login

Hi, i don't know if anyone can help me. I'm really a novice to be honest. I have a site I'm working on and using some code I made with the help of a friend i set up a login system. It worked on the server we were using. But when i tried to adapt it to a different server for a website I needed this functionality for it doesn't seem to work.

Somewhere in the transition something has either been lost or not added. I'm sure I've cover all the bases. I know there will be more info from me but if anyone can think of any obvious reasons that would be great I can then start to tick them off the list!

I look forward to hearing from anyone!
Nov 9 '07 #1
19 1465
Atli
5,058 Expert 4TB
Hi. Welcome to TSDN!

There are so many reasons why that could be happening I barely know where to start. It would help if you could post your code here, so we could see if we spot anything specific.

The first things I'd look for is any code that relies on register_globals or something that loads resources from or links to an absolute path ("http://localhost/page.php" rather than "/page.php").

But as I say, it's impossible to say unless we can have a look at your code.
Nov 9 '07 #2
Ok bit of a mess but here is the login code. its in a separate document called account.php. I have then used an include_once within the page i want it to appear. if that makes sense. anyway see below:


Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. if ($_SESSION["userid"]) {
  4.     ?>
  5. <link href="../../css/rollovers.css" rel="stylesheet" type="text/css" />
  6. <link href="../../css/styles.css" rel="stylesheet" type="text/css" />
  7. <link href="../../css/stylestext.css" rel="stylesheet" type="text/css" />
  8.  
  9.     <div id="signup"><div id="blogspacer"></div>
  10.         <p class="bodyboldblue">Logged in</p>
  11.         <?=$loginerror?>
  12.         <p class="loginbody">You are currently logged in as <strong>
  13.         <?=$member["member_name"]?>
  14.         </strong></p>    
  15.         <p><a class="loginbody" href='<?=$_SERVER['PHP_SELF']?>?logout=true<?=($_GET["id"]) ? "&id=".$_GET["id"] : "";?>'>Click here to log out</a></p>
  16.     </div>
  17.     <div id="blogspacer"></div>
  18.     <?
  19. }
  20. else {
  21.     ?>
  22.     <div id="signup"><div id="blogspacer"></div>
  23.     <form action='<?=$_SERVER['PHP_SELF']?><?=($_GET["id"]) ? "?id=".$_GET["id"] : "";?>' method='POST'/>
  24.     <p class="bodyboldblue">Blog Login</p>
  25.     <p class="loginbody">Username <br /><input name='un' type='text' class="loginbody" size='20'/>
  26.       </p><p class="loginbody">Password <br /><input name='pw' type='password' class="loginbody" size='20'/>
  27.       </p><p><input type='submit' class="loginbody" value='Login'/></p>
  28.     </div>
  29.     <div id="blogspacer"></div>
  30.     <?
  31. }
  32.  
  33. ?>
  34.  
Nov 9 '07 #3
Atli
5,058 Expert 4TB
Ahh ok.

Before you change anything, change the short-tags into real PHP tags.
Short-tags are disabled by default in PHP and you should avoid using them at all times. They are a little shorter, but honestly, their nothing but trouble.

That is:
Expand|Select|Wrap|Line Numbers
  1. # Change these tags:
  2. <? .. ?>
  3. <?=$var?>
  4.  
  5. # Into these tags:
  6. <?php ... ?>
  7. <?php echo $var; ?>
  8.  
Nov 9 '07 #4
Ahh ok.

Before you change anything, change the short-tags into real PHP tags.
Short-tags are disabled by default in PHP and you should avoid using them at all times. They are a little shorter, but honestly, their nothing but trouble.

That is:
Expand|Select|Wrap|Line Numbers
  1. # Change these tags:
  2. <? .. ?>
  3. <?=$var?>
  4.  
  5. # Into these tags:
  6. <?php ... ?>
  7. <?php echo $var; ?>
  8.  

Cool, i will sort this and let you know when its done. Thanks for your help so far.... and thanks in anticipation of your help to come!
Nov 9 '07 #5
Expand|Select|Wrap|Line Numbers
  1. <?php if ($_SESSION["userid"]) {?>
  2. <link href="../../css/rollovers.css" rel="stylesheet" type="text/css" />
  3. <link href="../../css/styles.css" rel="stylesheet" type="text/css" />
  4. <link href="../../css/stylestext.css" rel="stylesheet" type="text/css" />
  5.  
  6.     <div id="signup"><div id="blogspacer"></div>
  7.         <p class="bodyboldblue">Logged in</p>
  8.         <?php echo $loginerror?>
  9.         <p class="loginbody">You are currently logged in as <strong>
  10.         <?php echo $member["member_name"]?>
  11.         </strong></p>    
  12.         <p><a class="loginbody" href='<?php echo $_SERVER['PHP_SELF']?>?logout=true<?php echo ($_GET["id"]) ? "&id=".$_GET["id"] : "";?>'>Click here to log out</a></p>
  13.     </div>
  14.     <div id="blogspacer"></div>
  15.     <?php
  16. }
  17. else {
  18.     ?>
  19.     <div id="signup"><div id="blogspacer"></div>
  20.     <form action='<?php echo $_SERVER['PHP_SELF']?><?=($_GET["id"]) ? "?id=".$_GET["id"] : "";?>' method='POST'/>
  21.     <p class="bodyboldblue">Blog Login</p>
  22.     <p class="loginbody">Username <br /><input name='un' type='text' class="loginbody" size='20'/>
  23.       </p><p class="loginbody">Password <br /><input name='pw' type='password' class="loginbody" size='20'/>
  24.       </p><p><input type='submit' class="loginbody" value='Login'/></p>
  25.     </div>
  26.     <div id="blogspacer"></div>
  27.     <?php
  28. }
  29.  
  30. ?>
  31.  
Ok so i have changed the short tags. It still does nothing when i try to log in. What do you think the next step is?
Nov 12 '07 #6
Atli
5,058 Expert 4TB
I can't see anything wrong with that particular code, except that you missed one short-tag in line 20.

There doesn't seem to be any code there to process the form data that is posted if the Session variable in line 1 is false, which I would guess is the code that actually logs the user in. Could the problem be there?
Nov 12 '07 #7
I can't see anything wrong with that particular code, except that you missed one short-tag in line 20.

There doesn't seem to be any code there to process the form data that is posted if the Session variable in line 1 is false, which I would guess is the code that actually logs the user in. Could the problem be there?
Well from what you said in my limited knowledge I would have thought that that might be a problem, however, it is the same code as as i used before, which worked. Grr this is complicated. The thing that bugs me is that it seems as if its not even processing anything. When you submit illegal characters or incorrect login it doesnt come up with the error message that has been set up.

I will cross reference this with my old files and see if i can see anything in the code.
Nov 12 '07 #8
Ok i have racked my brains and cant see or find anything that is different to the other version i did (that worked) other than stylesheets etc.

You mentioned:

There doesn't seem to be any code there to process the form data that is posted if the Session variable in line 1 is false, which I would guess is the code that actually logs the user in. Could the problem be there?
Could you suggest what changes i could make to correct this... so sorry as you can tell I'm very, very poor at this! thanks for your help.
Nov 12 '07 #9
Atli
5,058 Expert 4TB
I could probably see if there are problems with the code, if I could see it :)
Just the part where you fetch the POST values and where you log the user in.

My first guess would be it has something to do with the register_globals directive, but there is really no way to tell unless I see the code.

Just out of curiosity, which version of PHP did this code work on? And which version are you trying to use it on now?

Could you create a new .php file with the following content, run it and find the value of the 'short_open_tag' directive and the 'register_globals' directive?
Expand|Select|Wrap|Line Numbers
  1. <?php echo phpinfo(); ?>
  2.  
Nov 12 '07 #10
LacrosseB0ss
113 100+
From my previous experiences, ASP and such will not work on Linux servers. Is the same true for the reverse? i.e. Will PHP work on a Windows server? Off the top of my head that's what I am thinking.

This Article claims some versions of Windows do not support PHP. And some PHP versions aren't set up to run. You can read the article for more.

Now, I could just be blowing smoke. I don't really know if this is correct or not. Just throwing ideas out there but I know ASP won't work on Linux (where PHP can be used). Perhaps your old server was Linux based and the new one is Windows based. I'd contact your server owner to find out.

- LB
Nov 13 '07 #11
From my previous experiences, ASP and such will not work on Linux servers. Is the same true for the reverse? i.e. Will PHP work on a Windows server? Off the top of my head that's what I am thinking.

This Article claims some versions of Windows do not support PHP. And some PHP versions aren't set up to run. You can read the article for more.

Now, I could just be blowing smoke. I don't really know if this is correct or not. Just throwing ideas out there but I know ASP won't work on Linux (where PHP can be used). Perhaps your old server was Linux based and the new one is Windows based. I'd contact your server owner to find out.

- LB
Hi thanks for the suggestion but it does have PHP installed on the server. I made sure of that when setting up the account. It has PHPmyAdmin pre-installed. I think it might be something to do with PHP 4 or 5 or something!

thanks.
Nov 13 '07 #12
I could probably see if there are problems with the code, if I could see it :)
Just the part where you fetch the POST values and where you log the user in.

My first guess would be it has something to do with the register_globals directive, but there is really no way to tell unless I see the code.

Just out of curiosity, which version of PHP did this code work on? And which version are you trying to use it on now?

Could you create a new .php file with the following content, run it and find the value of the 'short_open_tag' directive and the 'register_globals' directive?
Expand|Select|Wrap|Line Numbers
  1. <?php echo phpinfo(); ?>
  2.  
Ok i ran the PHP info document.

The short_open_tag is set to 'on' and the register_globals is also set as 'on'

does that help?

It is also PHP 4.... 4.4.7 to be exact. Im pretty sure the PHP im using is 4.

I noticed that the Register_globals on the previous server i used was set to off. Does this make a difference... it was also using PHP 4.4.6

hope some of this makes sense.
Nov 13 '07 #13
I have been in touch with the hosting company as i figured they would have to change the register_globals. they said that there is a .htaccess file on the live directory already that i can access and change.

Only, showing my inexperience and lack of knowledge again, i dont know how to get it. Ive looked through dreamweaver and cant see it. I used an independent FTP client and i can see the .htaccess file but cant download a copy to edit.

If anyone can shed some light on this that would be great. Thanks.
Nov 13 '07 #14
Atli
5,058 Expert 4TB
I wouldn't worry about changing that. If both the 'register_globals' and the 'short_open_tags' are on, neither of them will cause your code to stop functioning.

Now we know that neither of those two are the cause of your problem, we really need to see the login code to have any chance of finding the problem.

If you could find the login code and post it here, I could look through it and see if I spot anything that may be causing this.
Nov 13 '07 #15
Ok below is the code you have seen before which is the login:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if ($_SESSION["userid"]) {
  4.     ?>
  5. <link href="../../css/styles.css" rel="stylesheet" type="text/css" />
  6. <link href="../../css/stylestext.css" rel="stylesheet" type="text/css" />
  7. <link href="../../css/rollovers.css" rel="stylesheet" type="text/css" />
  8.  
  9.     <div id="signup"><div id="blogspacer"></div>
  10.         <p class="bodyboldblue">Logged in</p>
  11.         <?php echo $loginerror?>
  12.         <p class="loginbody">You are currently logged in as <strong>
  13.         <?php echo $member["member_name"]?>
  14.         </strong></p>    
  15.         <p><a class="loginbody" href='<?php echo $_SERVER['PHP_SELF']?>?logout=true<?php echo($_GET["id"]) ? "&id=".$_GET["id"] : "";?>'>Click here to log out</a></p>
  16.     </div>
  17.     <div id="blogspacer"></div>
  18.     <?php
  19.     }
  20.     else {
  21.     ?>
  22.  
  23.     <div id="signup"><div id="blogspacer"></div>
  24.     <form action='
  25.     <?php echo $_SERVER['PHP_SELF']?>
  26.     <?php ($_GET["id"]) ? "?id=".$_GET["id"] : "";?>' method='POST'/>
  27.     <p class="bodyboldblue">Blog Login</p>
  28.     <p class="loginbody">Username <br /><input name='un' type='text' class="loginbody" size='20'/>
  29.       </p><p class="loginbody">Password <br /><input name='pw' type='password' class="loginbody" size='20'/>
  30.       </p><p><input type='submit' class="loginbody" value='Login'/></p>
  31.     </div>
  32.     <div id="blogspacer"></div>
  33.  
  34. <?php
  35. }
  36. ?>
  37.  
then the next bit of code is...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         $filter[] = "blog_type = 1";
  3.         if ($_SESSION["userid"]) {
  4.         $filter[] = "blog_type = 2";
  5.         $filter[] = "(blog_type = 3 && memberID = ".$_SESSION["userid"].")";
  6.         } // end if ($_SESSION["userid"])
  7.         $sql = "SELECT * FROM blogs WHERE ".implode(" OR ",$filter);
  8.         $result = mysql_query($sql);
  9.         @ $rows = mysql_num_rows($result);
  10.         if ($rows > 0) {
  11.         while($data = mysql_fetch_array($result)) {
  12.             $sql = "SELECT member_name FROM members WHERE memberID = ".$data["memberID"];
  13.             $author_result = mysql_query($sql);
  14.             $author_name = mysql_fetch_array($author_result);
  15.             if ($data["blog_type"] == 1) $type = "Public";
  16.             elseif ($data["blog_type"] == 2) $type = "Personal";
  17.             elseif ($data["blog_type"] == 3) $type = "Private";
  18.             echo "<p><a href='view.php?id=".$data["blogID"]."'>".$data["blog_name"]."</a> by ".$author_name["member_name"]." (".$type.")</p>";
  19.         } // end while($data = mysql_fetch_array($result))
  20.         } // end if ($rows > 0)
  21.         else {
  22.         ?>Sorry, but there are currently no blogs available for you to peruse.
  23.         <p>Please try back again in a few days.</p>
  24.  
  25.         <?php
  26.         } // end if ($rows > 0) else
  27.         ?>
  28.  
  29.         </div>
  30.  
  31.         <div id="bloglogin">
  32.         <?php include_once($_SERVER['DOCUMENT_ROOT']."/common/panel/account.php"); ?>
  33.         </div>
  34.  
Nov 13 '07 #16
Another question... how would i go about finding out whether my server is set up to run sessions?
Nov 13 '07 #17
Atli
5,058 Expert 4TB
I still can't find any login code there.

The first example you posted appears to show you a logout page if you are logged in, or print a login form if you are not. But there is no code to process the data sent by the login form.

The second code seems to fetch blog entries from a MySQL database and display to the user. Again, there is no code here that will log a user in.

Are you sure there is any such code?
Could it be possible that you forgot to copy it from your old project?
That would certainly explain why the functionality won't work.

As to finding out if your server supports sessions.
Try this code. If you server supports sessions, the sessionID should stay the same, and the message should never change. No matter how much you refresh the page.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   # Start session and print the session ID
  3.   session_start();
  4.   echo "Session ID: ". session_id() ."<br />";
  5.  
  6.   # Set a random message if it isn't already set.
  7.   if(!isset($_SESSION['message'])) {
  8.     $textArray = array("First", "Second", "Third");
  9.     $_SESSION['message'] = $textArray[mt_rand(0, 2)];
  10.   }
  11.  
  12.   # Print the message
  13.   echo "Message: {$_SESSION['message']}<br />";
  14. ?>
  15.  
Nov 13 '07 #18
Ok so now i have the code that communicates with the database to check login and password is correct etc.

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3.     session_start();
  4.     function display_array($array) {
  5.         echo "<pre>";
  6.         print_r($array);
  7.         echo "</pre>";
  8.         return true;
  9.     } // function display_array($array)
  10.     function parseContent($content) {
  11.         $content = str_replace("<ul>","\n<ul>\n",$content);
  12.         $content = str_replace("<li>","\n<li>\n",$content);
  13.         $content = str_replace("</li>","\n</li>\n",$content);
  14.         $content = str_replace("</ul>","\n</ul>\n",$content);
  15.         $lines = explode("\n",$content);
  16.         $add_paragraph_tags = true;
  17.         foreach($lines as $line) {
  18.             $line = trim($line);
  19.             if (!empty($line)) {
  20.                 if ($line == "<ul>") $add_paragraph_tags = false;
  21.                 elseif ($line == "</li>") $add_paragraph_tags = false;
  22.                 if ($add_paragraph_tags) $output .= "<p>".$line."</p>\n";
  23.                 else $output .= $line."\n";
  24.                 if ($line == "</ul>") $add_paragraph_tags = true;
  25.                 elseif ($line == "<li>") $add_paragraph_tags = true;
  26.                 $lines_output[] = $line;
  27.             } // end if (!empty(trim($line)))
  28.         } // end foreach($lines as $line)
  29.         return $output;
  30.     } // end function parseContent($content)    
  31.     $db = mysql_pconnect("localhost","***************","*****************");
  32.     mysql_select_db("******************");
  33.  
  34.     // If you are logging in do this
  35.     if ($_POST["un"]) {
  36.         $result = mysql_query("SELECT * FROM members WHERE member_username = '".$_POST["un"]."' AND member_password = PASSWORD('".$_POST["pw"]."')");
  37.         @ $row = mysql_num_rows($result);
  38.         if ($row > 0) {
  39.             $member = mysql_fetch_array($result);
  40.             mysql_query("UPDATE members SET member_lastlogin = NOW() WHERE memberID = ".$member["memberID"]);
  41.             $_SESSION["userid"] = $member["memberID"];
  42.         } // end if ($row > 0)
  43.         else $loginerror = "<p><strong>Could not log you in. Username and password do not match!</strong></p>";
  44.     } // end if ($_POST["un"])
  45.  
  46.     // This code logs you out
  47.     if ($_GET["logout"]) {
  48.         unset($_SESSION["userid"]);
  49.     } // end if ($row > 0) else
  50.  
  51.     if (!empty($_SESSION["userid"])) {
  52.         $result = mysql_query("SELECT * FROM members WHERE memberID = '".$_SESSION["userid"]."'");
  53.         @ $row = mysql_num_rows($result);
  54.         if ($row > 0) {
  55.             $member = mysql_fetch_array($result);
  56.         } // end if ($row > 0)
  57.         else {
  58.             unset($_SESSION["userid"]);
  59.         } // end if ($row > 0) else
  60.     } // end if (!empty($_SESSION["userid"]))
  61.  
  62. ?>
  63.  
Nov 14 '07 #19
Atli
5,058 Expert 4TB
Ok, I see a few things there I'd like to mention.

First, and most likely to solve your problem, line 52. I assume that the SQL statement there is meant to find out if the user with the given user ID actually exists.
The problem is that you are enclosing the ID in quote tags, which it should not be. Numeric values should not be quoted.

Second. You use the mysql_pconnect function to connect MySQL. Is there any specific reason for this?
If not, you may be better of using the mysql_connect function.

Lastly. The way your code is built, it would be possible to both log in and log out at the same time. I would add a else clause to the if statement that checks if the POST data has been sent so this would not be possible.
It should never happen anyways so the only thing you are doing with this is bypass the last two if statements if you are login in.
Nov 14 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: tarAnta | last post by:
We installed ez publish 3.1 on Linux Mandrake 9.1 We used graphic setup, following all instructions. Now we login as admin in http://localhost/ezpublish/index.php/admin/login but we see many...
0
by: Ralf Hornbeck | last post by:
Hi, I have just uploaded an older PHP project I have written by myself up to my new webserver. On this server PHP is running in version 4.3.2 and this seems to result in some trouble, since the...
0
by: Michael Fork | last post by:
Note: I pasted the code the attachments as plain text after the message (I wasn't able to post it with an attachment...) Attached are the XSL and XML files that I am having problems with. I am...
3
by: headware | last post by:
I have an issue that I've been encountering in an ASP application I'm working on. Most of the application is written in ASP, but there is one page written in ASP.NET. The ASP.NET page needs to have...
6
by: Andrew | last post by:
Hell-hohoho to all... Just begun working with asp.net linking to sqlServer 2000, had some problems with the (null) user, but previous posts have got me past that by storing an identity in the...
2
by: Gary Coutts | last post by:
Hi, I am have problems redirecting from a login page. The login page is simple, with just 2 textboxes and one button. On the button click the routine below is called: I am using: Visual...
0
by: Sonnich | last post by:
Hi all! I seem to still have problems with MySQL. I wanted to create a new instance in order to run some tests of DB sizes. I want to create a new db, user etc... using teh command line client...
0
by: kang jia | last post by:
hi i have small problems occurred in my login function, which i use Django to build, in my template which is login.html, the code is like the following: <html> <head>...
3
by: Barely Audible | last post by:
Running 10.2. Sudden problems with my suse box - when i try to start it up it ignores the auto login and presents me with the login page. Entering the usual login on that page results in a black...
5
by: dipperdan | last post by:
Hi, I'm trying to use sessions to create a login system to administer a website - add new info to database,etc but i'm running into some problems. The first page login.php seems to work okay, it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.