Akshay123 Posted June 21, 2010 Share Posted June 21, 2010 Hi I'm completely new to PHP, and I am having trouble with a piece of code I wrote: this is for a login script. to help you understand, please note that this script is located through this path: http://localhost/oauth/login/login.php <?php if($_GET['error'] == "incorrect"); // so if the URL is like ?error=incorrect { include 'loginerror.php'; // then if should show http://localhost/oauth/login/loginerror.php } if(isset($_COOKIE['LOGIN'])); // however, if the cookie 'LOGIN' exists { if (isset($_COOKIE['REFER'])); // and if the cookie 'REFER' also exists { header('Location: /d.html'); // it should redirect to // http://localhost/d.html } else; // however... if the cookie 'LOGIN' exists, but not the cookie 'REFER' { header('Location: /account.html'); // then the php should redirect to http://localhost/account.html } } else; // otherwise, if no query string is passed, and no cookies exist { include 'reglogin.php'; // redirect to http://localhost/oauth/login/reglogin.php } ?> well, if you can help me with this, can you help me with this also? the only part that doesn't work is the part labled 'TROUBLESOME PART' everything else works <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="mypassword"; // Mysql password $db_name="dbUsers"; // Database name $tbl_name="members"; // 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 // TROUBLESOME PART if($count==1){ // if the user & pass is correct ($count), then it will set a cookie // i am not using session_REGISTER at this time, so those lines are commented //session_register("myusername"); //session_register("mypassword"); setcookie(LOGIN, $myusername, 36000000000, "/"); // if user & pass are correct, set that cookie if(isset($_COOKIE['REFER'])){ // then if the cookie 'REFER' exists (mentioned before) header( 'Location: /d.html' ) ; // redirect to http://localhost/d.html } else; // otherwise, if the username and password is correct and 'REFER' doesn't exist... { header( 'Location: /account.html' ) ; // redirect to http://localhost/account.php } } else { // if the user and pass are incorrect, it will go to /login.html?error=incorrect, which will actually show /oauth/login/loginerror.php header("/oauth/login/login.php?error=incorrect'); } ?> and finally, also one small php problem... located at http://localhost/oauth/login/endsession.php <?php if(isset($_COOKIE['LOGIN'])){ // if the cookie login exists $m = ($_COOKIE['LOGIN']); setcookie(LOGIN, $m, time()-36000000000, "/"); // delete it if(isset($_COOKIE['REFER'])){ // if the cookie 'refer' exists $f = ($_COOKIE['REFER']); setcookie(REFER, $f, time()-3600, "/"); // delete it } else { header( 'Location: /d.html' ); // if the cookie 'refer' doesn't exist, go to http://localhost/d.html } } else; // if the cookie login doesn't exist { header( 'Location: /d.html' ) ; redirect back to http://localhost/d.html } ?> if you can help me in any way with any of these php scripts, please reply. all help is welcome thank you Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/ Share on other sites More sharing options...
kenrbnsn Posted June 21, 2010 Share Posted June 21, 2010 What errors are you getting? Ken Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/#findComment-1075237 Share on other sites More sharing options...
Akshay123 Posted June 21, 2010 Author Share Posted June 21, 2010 error for http://localhost/oauth/login/login.php Parse error: syntax error, unexpected T_ELSE in C:\Program Files\XAMPP\xampp\htdocs\oauth\login\login.php on line 12 error for http://localhost/oauth/login/checklogin.php (the second piece of code) no error comes up, the page is just white (blank), even the source code. error for http://localhost/oauth/login/endsession.php not really an error, the page just comes back to http://localhost/d.html, but the cookies don't disappear Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/#findComment-1075246 Share on other sites More sharing options...
kenrbnsn Posted June 21, 2010 Share Posted June 21, 2010 Remove the semi-colons on the "if" & "else" lines. <?php if($_GET['error'] == "incorrect") // so if the URL is like ?error=incorrect { include 'loginerror.php'; // then if should show http://localhost/oauth/login/loginerror.php } if(isset($_COOKIE['LOGIN'])) // however, if the cookie 'LOGIN' exists { if (isset($_COOKIE['REFER'])) // and if the cookie 'REFER' also exists { header('Location: /d.html'); // it should redirect to // http://localhost/d.html } else // however... if the cookie 'LOGIN' exists, but not the cookie 'REFER' { header('Location: /account.html'); // then the php should redirect to http://localhost/account.html } } else // otherwise, if no query string is passed, and no cookies exist { include 'reglogin.php'; // redirect to http://localhost/oauth/login/reglogin.php } ?> You have a semi-colon after the "else" in the other segments also. Remove them. They don't belong there. Ken Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/#findComment-1075253 Share on other sites More sharing options...
Akshay123 Posted June 21, 2010 Author Share Posted June 21, 2010 Thank You!!!! most of the problems are fixed, except for one small issue script #3, http://localhost/oauth/login/endsession.php, still won't delete the cookies. Can you help me with that? the new code I am using now, after making corrections, is <?php if(isset($_COOKIE['LOGIN'])){ // if the cookie login exists $m = ($_COOKIE['LOGIN']); setcookie(LOGIN, $m, time()-36000000000, "/"); // delete it if(isset($_COOKIE['REFER'])){ // if the cookie 'refer' exists $f = ($_COOKIE['REFER']); setcookie(REFER, $f, time()-3600, "/"); // delete it } else { header( 'Location: /d.html' ); // if the cookie 'refer' doesn't exist, go to http://localhost/d.html } } else // if the cookie login doesn't exist { header( 'Location: /d.html' ) ; //redirect back to http://localhost/d.html } ?> thanks Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/#findComment-1075271 Share on other sites More sharing options...
kenrbnsn Posted June 21, 2010 Share Posted June 21, 2010 When using the function setcookie, the cookie name should be a string: <?php if(isset($_COOKIE['LOGIN'])){ // if the cookie login exists $m = ($_COOKIE['LOGIN']); setcookie('LOGIN', $m, time()-3600, "/"); // delete it if(isset($_COOKIE['REFER'])){ // if the cookie 'refer' exists $f = ($_COOKIE['REFER']); setcookie('REFER', $f, time()-3600, "/"); // delete it } else { header( 'Location: /d.html' ); // if the cookie 'refer' doesn't exist, go to http://localhost/d.html } } else // if the cookie login doesn't exist { header( 'Location: /d.html' ) ; //redirect back to http://localhost/d.html } ?> Ken Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/#findComment-1075276 Share on other sites More sharing options...
Akshay123 Posted June 22, 2010 Author Share Posted June 22, 2010 thank you, it works now Link to comment https://forums.phpfreaks.com/topic/205468-php-parse-error-help/#findComment-1075442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.