PHP - Login With Manual Code
Hi,
I'm trying to login oscommerce with manual code. but unable to do that. all entries going to database but don't understand what is missing??? here is my code Code: [Select] $email_address = $_REQUEST['txtemail']; $password = $_REQUEST['password']; $check_customer_query = mysql_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from customers where customers_email_address = '" . $email_address . "'"); if (mysql_num_rows($check_customer_query)> 0) { $check_customer = mysql_fetch_assoc($check_customer_query); if (!tep_validate_password($password, $check_customer['customers_password'])) { echo "password not found."; }else { tep_session_recreate(); $check_country_query = mysql_query("select entry_country_id, entry_zone_id from address_book where customers_id = '" . (int)$check_customer['customers_id'] . "' and address_book_id = '" . (int)$check_customer['customers_default_address_id'] . "'"); $check_country = mysql_fetch_array($check_country_query); $customer_id = $check_customer['customers_id']; $customer_default_address_id = $check_customer['customers_default_address_id']; $customer_first_name = $check_customer['customers_firstname']; $customer_country_id = $check_country['entry_country_id']; $customer_zone_id = $check_country['entry_zone_id']; tep_session_register('customer_id'); tep_session_register('customer_default_address_id'); tep_session_register('customer_first_name'); tep_session_register('customer_country_id'); tep_session_register('customer_zone_id'); mysql_query("update customers_info set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$customer_id . "'"); anyone have any idea about? Similar TutorialsHi, I'm just trying out some basic code and playing around with passing variables by reference and i was reading this on the php manual at this page http://php.net/manual/en/language.references.pass.php : No other expressions should be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid: <?php function foo(&$var) { $var++; } function bar() // Note the missing & { $a = 5; return $a; } foo(bar()); // Produces fatal error since PHP 5.0.5 foo($a = 5); // Expression, not variable foo(5); // Produces fatal error ?> So, i decided to try it out myself like i always do, and i noticed that i'm not getting an error when i do foo(bar()); i.e calling bar() without the & in the function declaration. Infact it works perfectly fine and returns an incremented $a after its passed to foo(). Likewise foo($a = 5); also works great and returns an incremented $a after being passed to foo(). Is this a mistake in the manual or am i missing something? Running PHP 5.3.2-1ubuntu4.5 So I am new to all this coding and I am making a small website, which has to have a login and something is not working properly. My login user/pass processing code looks like this <?php $host = 'xxxx'; // Host name Normally 'LocalHost' $user = 'xxxx'; // MySQL login username $pass = 'xxxx'; // MySQL login password $database = 'members'; // Database name $table = 'members'; // Members name $username = $_POST["username"]; $password = $_POST["password"]; $connection = mysql_connect("xxxx", "$user", "$pass"); if (!$connection) { die("Database connection failed: " . mysql_error()); } else { echo "Everything is fine!<br />"; } mysql_select_db("xxxx",$connection) or die(mysql_error()); $result = mysql_query("SELECT * FROM members WHERE usr='$username' and pass='$password'",$connection) or die(mysql_error()); $count=mysql_num_rows($result); if($count==1){ session_start(); session_register("myusername"); session_register("mypassword"); header("location:Login_Success.php"); } else { echo "Wrong Username or Password"; } ?> So it all continues well and transfers me to Login_Success.php, where the code looks like this <? if(!session_is_registered(myusername)){ header("location:MainPage.htm"); } ?> <html> -----my html code here, which makes no difference---- The problem is that it sends me to MainPage.htm and I can't really figure out why. As ive said im new to all of this. I figured that the session did not stay logged in, when it changed pages for some odd reason? THANK YOU! Hey guys I've been writing this login code and ive been having some minor problems i dunno what seemds to be the problem ive tried everything :s Here's the html part of the login, the username and pass are sent by post to login.php below to compare with the ones in the database Code: [Select] <form method="POST" action="login.php"> Username : <input type="text" name="username"> Password : <input type="password" name="password"> <input type="submit" value="Login"> </form>$connect=mysql_connect("localhost","swcri_tarakji","xxxxxxxxxx"); mysql_select_db("swcri_working",$connect) or die (mysql_errno().":<b> ".mysql_error()."</b>"); $select_user = mysql_query('select * from users where username = "' . $_POST['username'] . '" and password = "' . md5($_POST['password'] . '"')); if (mysql_num_rows($select_user) != 0) { session_start(); session_register('authorized'); $_SESSION['authorized'] = true; header("Location: protected.php"); exit; } else { header("Location: login_form.php"); exit; } i get the following errors when i try to login : Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/swcri/public_html/working/login.php on line 19 Warning: Cannot modify header information - headers already sent by (output started at /home/swcri/public_html/working/login.php:10) in /home/swcri/public_html/working/login.php on line 30 Pleaassseee help me hi i am reading about sessions in the php manual. what does this mean: If register_globals is disabled, only members of the global associative array $_SESSION can be registered as session variables. The restored session variables will only be available in the array $_SESSION. ? I have a pretty basic PHP log in code connected to a database of register users. However, it's not allowing any users to enter? Could someone please review the code and let me know if you find any errors? //Create query $qry="SELECT * FROM customers WHERE username='$login' AND password='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['fname']; $_SESSION['SESS_LAST_NAME'] = $member['lname']; session_write_close(); header("location: key_catalog.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> I created a login form for my system and I don't sure that it's enought for security to protect my website? include("database.php"); session_start(); if($_SERVER["REQUEST_METHOD"] == "POST") { // username and password sent from form $stmt = $conn->prepare("SELECT Sale_ID FROM tb_sales WHERE Login_Name = ? AND Login_Password = ? LIMIT 1"); $stmt->bind_param("ss", $_POST['username'], $_POST['password']); $stmt->execute(); $res = $stmt->get_result(); $count = mysqli_num_rows($res); if($count == 1) { // session_register("myusername"); $_SESSION['login_user'] = $_POST['username']; echo "Login Succcess"; //header("location: index.php"); }else { echo "Your Login Name or Password is invalid"; } }
i need help for writing a code that will get only the base url and will return you the login url, for example Base url = www.yahoo.com and in return you will get the yahoo login page url where you input the user name and password, remember the code should be dynamic i.e. what ever base url you give it will return the login/sign in url of the corrosponding url. please help in this regard. Regards [ m ]printf[/ m]produces a link to
php.net/<span>printf
Unless you use nobbc tags, then it works fine ???
Edited by Barand, 24 November 2014 - 02:25 PM. Hi there, I am wondering if you guys can help me make it so my session times out after a previously set time. I have researched this and found no luck. Here is my code.... Code: [Select] <?php session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; ?> Thanks in advance! Hello all, My knowledge in PHP is growing everyday as I try out more stuff but I really didn't understand this bit : "Note: Please note that the ternary operator is a statement, and that it doesn't evaluate to a variable, but to the result of a statement. This is important to know if you want to return a variable by reference. The statement return $var == 42 ? $a : $b; in a return-by-reference function will therefore not work and a warning is issued in later PHP versions. ". taken from the page : http://www.php.net/manual/en/language.operators.comparison.php From what I understood, if I was to use a ternery condition in the return statement, and return a referenced variable as a result, it shouldn't work? So this shouldn't work? $int = 10; function testReturn(&$referencedVariable) { return (1==1) ? $referencedVariable : FALSE; } echo testReturn($int); But it does. Anyways i'm pretty sure I didn't understand this right, so help with this is really appreciated Where in the PHP manual can I find information about input validation? I looked and I seem to not find it. I am intending to create my own email input validation. mysql_connect('', '', ''); mysql_select_db(''); if (isset($_POST['submit'])) { $user = mysql_real_escape_string($_POST['user']); $pass = mysql_real_escape_string($_POST['pass']); $sql = "SELECT id FROM login WHERE username = '$user' && `password` = MD5('$pass')"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $user & $pass are valid echo "You Logged In $user"; } else { // $user || $pass invalid echo "Invalid Login"; } } } Registration.php Code: [Select] <html> <head> <script type="text/javascript"> function a() { var x = document.login.username.value; var y = document.login.pass.value; if(x==""&& y=="") { alert("Please insert all message!"); return false; } if(x=="") { alert("Please insert an username!"); return false; } if(y=="") { alert("Please insert an password!"); return false; } } </script> </head> <?php session_start(); mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); //session_start(); $username = $_POST['username']; $password = $_POST['pass']; if (isset($_POST["submit"])) { $log = "SELECT * FROM regis WHERE username = '$username'"; $login = mysql_query($log); $number = mysql_num_rows($login); if ($number == 0) { print "That user does not exist in our database. <a href=registration.php><input type='button' value='Register'></a>"; } if ($number > 0) { $_SESSION['is_logged_in'] = 1; } if(!isset($_SESSION['is_logged_in'])) { } else { echo "<meta http-equiv='refresh' content='0; url=form2.php'>"; } } else { ?> <body> <table border="0"> <form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return a()"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td> <td><input type="text" name="username" maxlength="40"></td></tr> <tr><td>Password:</td> <td><input type="password" name="pass" maxlength="50"></td></tr> <tr><td><input type="submit" name="submit" value="Register"></a></td> <td><input type="submit" name="submit" value="Login"></td></tr> </form> </body> <?php } ?> </html> form2.php Code: [Select] <?php session_start(); if (!isset($_SESSION['is_logged_in'])) { header("Location:login.php"); die(); // just to make sure no scripts execute } ?> <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $n=$_POST['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$n','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt=":)" onClick="addsmiley(':)')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt=":)" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type="hidden" name="username" value="<?php echo $n;?>"> <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </body> </html> My problem is after i login it redirect to login page although im had put after login page its need to go to form2.php page may i know which problem because now only im learning session When I log in on my web-site it takes me to a php login-check page This is the error code that I am getting; Quote Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\login-check.php on line 26 This is the php code that i am using; Code: [Select] <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="deliverpizza"; // Database name $tbl_name="customer, admin, staff"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_privelage.php"); } else { } ?> Hello, for some reason I am unable to get the following code to work: Code: [Select] <?php echo "<h1>Login</h1>"; if ($_SESSION['uid']) { echo " You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here</a>!\n"; } else { if (!$_POST['submit']) { echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./login.php\">\n"; echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n"; echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Login\"></td></tr>\n"; echo "</form></table>\n"; }else { $user = addslashes(strip_tags(($_POST['username']))); $pass = addslashes(strip_tags($_POST['password'])); if($user && $pass){ $sql = "SELECT id FROM `users` WHERE `username`='".$user."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0){ $sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".md5($pass)."'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) > 0){ $query = mysql_query("SELECT locked FROM `users` WHERE `username`='".$user."'"); $row2 = mysql_fetch_assoc($query); $locked = $row2['locked']; $query = mysql_query("SELECT active FROM `users` WHERE `username`='".$user."'"); $row3 = mysql_fetch_assoc($query); $active = $row3['active']; $query = mysql_query("SELECT email FROM `users` WHERE `username`='".$user."'"); $row3 = mysql_fetch_assoc($query); $email = $row3['email']; if ($active ==1){ if ($locked == 0){ $date = date("j")."<sup>".date("S")."</sup> ".date("F, Y"); mysql_query("UPDATE users SET last_login='$date' WHERE username='$user'"); $row = mysql_fetch_assoc($res2); $_SESSION['uid'] = $row['id']; $previous = $_COOKIE['prev_url']; echo " You have successfully logged in as " . $user . "<br><br><a href='" . $previous . "'>Click here</a> to go to the previous page.\n"; }else { echo "Your acount has been locked out due to a violation of the rules, if you think there has been a mistake please <a href='contact.php'>contact us</a>."; } } else { echo "You need to activate your account! Please check your email ($email)"; } }else { echo " Username and password combination are incorrect!\n"; } }else { echo " The username you supplied does not exist!\n"; } }else { echo " You must supply both the username and password field!\n"; } } } ?> It says that I have logged in successfully but the session is not created. You can find the script here and log in with the username "test" and the password "testing". I'm not sure what more information I should add. Thanks, Cameron I have this working code except I can't redirect to a thank you page when a new user registers. When they login it works without issue. I just don't know where or what to put for the registration part.
Here is my Code. Any help would be much appreciated.
<?php Hello, I have a wordpress site using Thesis 2.1 theme and I am displaying "excerpts" for each post on homepage.. I don't want to add <!-- more --> to each post and I want to show sth different, sth more valuable on the homepage to my readers.. Thats why I use excerpts. I added this line of code to my custom.php file: function new_excerpt_more($more) { global $post; return ' <a href="'. get_permalink($post->ID) . '">Continue Reading...</a>'; } add_filter('excerpt_more', 'new_excerpt_more');It added a "continue reading.." link to the posts that I haven't yet defined excerpt.. So, If nothing is written on the excerpt area of that post, it shows some part of the post and adds a "continue reading.." link to it on the homepage. But if I have written sth in the excerpt area of the post, it does shows the excerpt, but doesn't add the "continue reading.." link at the end.. I will be happy if you may help me on this, this drives me nuts currently! [/size] MERGED So basically, what I am trying to do is, adding read more tag to custom excerpts which we define manually. Here is another code I tried but had no luck again! //* Changing excerpt more - only works where excerpt IS hand-crafted function manual_excerpt_more( $excerpt ) { $excerpt_more = ''; if( has_excerpt() ) { $excerpt_more = ' <a href="' . get_permalink() . '" rel="nofollow">[Read more]</a>'; } return $excerpt . $excerpt_more; } add_filter( 'get_the_excerpt', 'manual_excerpt_more' ); Edited by Ch0cu3r, 09 November 2014 - 01:18 PM. Hello I have the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM players WHERE ((NOT inactive_player) AND ((players.Player_Last_Name = 'p' at line 3 I think my error is in the statement below... Code: [Select] echo "1"; $getNewPlayers = "SELECT players.Player_number, players.Player_name, FROM players WHERE ((NOT inactive_player) AND ((players.Player_Last_Name = 'player_find%'))) ORDER BY player_name"; $rsNewPlayers = mysql_query($getNewPlayers, $link) or die (mysql_error()); $varNewCount = mysql_num_rows($rsNewPlayers); echo $varNewCount['Player_name']; Can you tell me where the error is and how I might go about to fix it? Thanks, Hello forum. I'm new here, but I've been reading and finding useful things for a while now. I'm still new to PHP and I need a little help. I'm doing a school project and I have some things I want to do, but do not know how to write it down in PHP. I think I'll ask a lot of questions this week, and I hope I will get some help.. For start I want to ask this: I've been using Code: [Select] mysql_fetch_array() for doing loops and populating check-boxes. And everything's working fine.. but what I want is to control the actual loop by clicking buttons. Let's say first time a while-do is run, my check-boxes get populated from the database and every other loop the next data from the table is added.. pretty straightforward. I want to be able to populate once, then click "next" and the new data to be added and so on.. Code: [Select] <?php $tema = mysql_query("SELECT * from questions")or die(mysql_error()); function answer1($string) { $string1 = explode("/", $string); echo $string1[0]; } function answer2($string) { $string1 = explode("/", $string); echo $string1[1]; } while ($row=mysql_fetch_array($tema)) { echo mysql_fetch_array($tema); $tip=$row["tip"]; if ($tip==2) { $id=$row['prasanje_id']; $question=$row['question']; $answer=$row['answer']; ?> <label> <?php echo $question?></label><br> <input type="checkbox" name="CheckboxGroup1" value="checkbox" id="CheckboxGroup1_0" /> <?php answer1($tekst) ?></label> <label> <input type="checkbox" name="CheckboxGroup1" value="checkbox" id="CheckboxGroup1_1" /> <?php answer2($tekst) ?></label> <?php } } ?>I want an alternative to the while-do loop.. Is it possible to do this? Thanks!! well basically im trying to do that the 'subject says. ive done my homework and had around 10 examples of using curl, but none of them worked in my case. this is the final code i'm using <?php $cookiefile = '/temp/cookies.txt'; #2 ways ive tried doing #$data = array('edit[username]' => 'REMOVED', 'edit[password]' => 'REMOVED', 'edit[submit]' => 'Login'); $data = array('username] => 'REMOVED', 'password' => 'REMOVED', 'submit' => 'Login'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://pokerrpg.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch); curl_setopt($ch, CURLOPT_URL, 'http://pokerrpg.com/furniture_store.php'); $contents = curl_exec($ch); $headers = curl_getinfo($ch); echo $contents; curl_close($ch); unlink($cookiefile); ?> im not sure about the cookie file, but i just made a txt file to that location. and empty txt file. hope it's fine. the page i'm trying is http://pokerrpg.com, you can even look the source code that both of these fields do exist. when i run it, the output is a login page without logging in, so it does not log in. |