473,800 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems with my login

12 New Member
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
19 1488
LacrosseB0ss
113 New Member
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
twodelay
12 New Member
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
twodelay
12 New Member
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_global s 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_globa ls' 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_global s 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_global s 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
twodelay
12 New Member
I have been in touch with the hosting company as i figured they would have to change the register_global s. 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 Recognized Expert Expert
I wouldn't worry about changing that. If both the 'register_globa ls' and the 'short_open_tag s' 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
twodelay
12 New Member
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
twodelay
12 New Member
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 Recognized Expert Expert
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
twodelay
12 New Member
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 Recognized Expert Expert
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
1789
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 strange problems: - if we go to set up-->content and try to edit a class or press "new class" button nothing changes! - if we go to address http://localhost/ezpublish/index.php/demo/login/ under header buttons we receive this error: Module not found...
0
1899
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 project worked out pretty fine some weeks ago under PHP 4.2.3 (I think). My suggestion is that it has to do sth. with sessionhandling, but I am not sure. I don't think that the DB connection is responsible for the problems and I
0
3514
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 trying to extract the stock information after having downloaded the HTML and converted to XML (well-formed HTML) using XSL and XPATH and am unable. I am basing what I have done so far off of...
3
2855
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 access to the ASP Session data to run correctly. In order to achieve this I create my own HTTP request for a certain ASP page with the name of Session variable that I want is stored in the query string of the request. The requested ASP page...
6
1250
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 web.config file. However, I want to dyamically set the login info, from a prompted box. I'm aware of the security issues here, but I'll ignore that for now. The kb article I saw set the following info in the connection string of the sql...
2
1995
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 Studio 2003 Version 7.1.3008 Framework 1.1 Version 1.1.4322 SP1 Windows XP Pro Version 2002 SP2
0
961
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 I removed the old instance, and created a new one. Could not login as root. Simply crashes. Service cannot start. Dont know why.
0
1328
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> <title>Login</title>
3
1085
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 screen, flash of things starting and then back to the login page. The root login works okay. Any clues would be gratefully appreciated!
5
1553
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 authenticates the user then takes them to the next page update_db.php but when i get to this page, it seems all the session data is lost :icon_conf login.php <?php session_start(); // we must never forget to start the session $errorMessage =...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.