How to redirect log in page

To whom is this concern I have problem,everything works
good my register form,my log in page,my datebase but my log in page doesn’t go where I want,that’s my index page.

http://www.webdesigngroup1999.com/mysqladmin/login.php?op=login that is page where I am going after enter right username and password.But I want to go on my idex.php page.

<?php session_start(); // dBase file include "dbConfig.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `dbUsers` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: members.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { //If all went right the Web form appears and users can log in echo ""; echo "Username: "; echo "Password: "; echo ""; echo ""; } ?>

"?op=login I tried to replace with index.php page but I am getting nothing.If anyone can help me right here or over the Skype I will appricate.

Based on what you have posted, the only place you are redirecting is on this line
[php]
// Redirect to member page
Header(“Location: members.php”);
[/php]
So change it to this
[php]
// Redirect to index page
Header(“Location: index.php”);
[/php]

I tried that and didn’t work.Any other suggestions .

It should work as is. You just do not have the correct address you want to redirect to. Also, Please post code inside the tags as it makes it easier for us to copy it to our programming tools.

You did not mention the name of this page of code. I assume it is login.php. And, that this code is called from your login-form page. And, lastly that it redirects into the page named index.php.

Here is your code with the index page added in as “fastsol” mentioned… I took the liberty of formatting it so I can read it. It should work. If not, you can add debugging lines to it. To do that, just add a "die (“Got Here 1”); and die(“Got Here 2”); etc inside each of your IF statements and find where the code is traveling thru. But, it does look good as far as I see except the actual redirect line. Also, you MUST make sure that the index.php is there and spelled correctly. One issue with PHP is that it is capital dependent. Therefore, index.PHP is not index.php and not Index.php. Sometimes it is just a spelling error.

page: login.php
[php]

<?php session_start(); // dBase file include "dbConfig.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `dbUsers` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: index.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { //If all went right the Web form appears and users can log in echo ""; echo "Username: "; echo "Password: "; echo ""; echo ""; } ?>

[/php]

One further note. You should make sure that the first few lines inside index.php is a check for the session variables to insure that only logged in members can be there. I think it should work. Let us know if you need further help…

I am really thankful because you are trying to help me ,and appreciate your time.But i tried all what you said and not let me to redirect from log in page to the index.php
www.webdeveloper.com/forum/showthread.php?265799-Login-amp-Registration-form-with-profile
This is website where i took those codes first five i copied and tried to make work.

I think that is problem here echo “<form action=”?op=login" method=“POST”>";
you see that "op?=login is coming on the end of my domain. www.webdesigngroup1999.com/mysqladmin/login.php?op=login (That is my page after i logged)

Couple more things won’t work either
This is my register.php page

<?php // dbConfig.php is a file that contains your // database connection information. This // tutorial assumes a connection is made from // this existing file. include ("dbConfig.php"); //Input vaildation and the dbase code if ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } // If we had problems with the input, exit with error if ($bInputFlag == false) { die( "Problem with your registration info. " /////This is not working after i tried to register already registered users i have blank page./////////////////// ."Please go back and try again."); } // Fields are clear, add user to database // Setup query $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; // Run query $r = mysql_query($q); // Make sure query inserted user successfully if ( !mysql_insert_id() ) { die(" User not added "); } else { // Redirect to thank you page. Header("Location: register.php?op=thanks"); //////////This is not working either i got blank page here too//////////////////// } } // end if //The thank you page else if ( $_GET["op"] == "thanks" ) { echo "

Thanks for registering!

"; /////////////////////This is not working either.///// } //The web form for input ability else { echo "\n"; echo "Username: \n"; echo "Password: \n"; echo "Email Address: \n"; echo "\n"; echo "\n"; } // EOF ?>

I am really good with css and html but PHP is my weak side.

Well, you did not show your code that was calling the PHP routine. You only showed the PHP code.

You can NOT do this: <form action="?op=login" method=“POST”>"

You need a page to accept the action. Something like this:

"

The “OP” is an parameter that is sent to the page before it. So, you need to send it somewhere. Then, in that file, you retrieve the OP parm with a $op=$_GET[‘op’]; Then, you can use the variable $op for whatever…

Hope that helps!

Still not working.I am getting blank page.In my index.php file I wrote word test I can’t see it.

When you get a “blank page” what is on the address bar?

If you are redirecting to the index page with a parm of ‘op’ you should see what it is on the address bar.
It should show you what you sent to the page. Just look up to the address bar and see what your code is sending to the index page.

Also, when you update your code, post the new code so we can see if you mad some sort of mistake in typing in the new code.

Let us know what is in your address line. Thanks.

I fix it :slight_smile: echo “<form action=“index.php” method=“POST”>”;

The code should look like that.After log in I see my index.php and word test.Thank you very much guys I am really thankful for your help.

But I have one more code if you ready to help to resolve that problem I have over the 30 day’s.That is another code and another website my log in page won’t check registered users( No match in our records, try again) to log in.My register form works perfect,actives by e-mail works perfect but log in page won’t, log in registered user,i can see them in my date base all informations

Well, show some code and we can help. One way that is good for debugging login’s is to just dump the SQL and see where the error is.

What I mean is you set up your query to check for the user and password.

$query=“SELECT * FROM members WHERE user=$username” or whatever you have in code.
Then you execute the query.

But, just display the query first and see where the error is. Something like die ($query);
This will kill your page and display the value inside of $query. Then you can look at the query that you are using and see what the REAL query is. Then, you will know what part of the query is bad.

Hope that made sense to you. If not, post some code on the where the query is created and where it calls the database. (Remember NOT to post any passwords here on the site!)

<?php /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ if ($_POST['email']) { //Connect to the database through our include include_once "connect_to_mysql.php"; $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); $password = preg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters $password = md5($password); // Make query and then register all database data that - // cannot be changed by member into SESSION variables. // Data that you want member to be able to change - // should never be set into a SESSION variable. $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Get member ID into a session variable $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; // Get member username into a session variable $username = $row["username"]; session_register('username'); $_SESSION['username'] = $username; // Update last_log_date field for this member now mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'"); // Print success message here if all went well then exit the script header("location: member_profile.php?id=$id"); exit(); } // close while } else { // Print login failure message to the user and link them back to your login page print '

No match in our records, try again

Click here to go back to the login page.'; exit(); } }// close if post ?> Login to your profile



Log in to your account here

Email Address:
Password:
 

This my code it is my log in page I don’t have errors I don’t see them,and I run sql SELECT * FROM members WHERE email=’$email’ AND password=’$password’ AND emailactivated=‘1’"); didn’t help.Right here I deleted password and name of datebase.By the way thanks for advice.The problem is between this code and datebase,like I said is not checking registered users to let them to log in.I see email and password in my datebase but when I trying to log in is said
No match in our records, try again.

I have used that same code before. It is basic code. The problem with it is that it does not check for each part of the query.

What I mean is that it doesn’t check for the user name separate from the password. It just says, go or no-go.

So, one problem I see in the code is that you do not check for caps or not. If the registration form was entered such as this: Name: “Ernie” and I tried to log in with “ernie” it would not work. It is hard to see what is wrong in your code without using some debugging code. That is what I meant by using the “DIE” command. But, with your current code, you can use this change to help you figure it out…

Where you currently have:
[php]
} else {
// Print login failure message to the user and link them back to your login page
print ‘

No match in our records, try again


Click here to go back to the login page.’;
exit();
}
[/php]

Make a temporary change to help you out. Just remember to remove it once you fix the errors:
[php]
} else {

// Temporary data dump for debugging
echo "email posted: " . $_POST[‘email’] . “
”;
echo "email stripped: " . $email . “
”;
echo "password posted: " . $_POST[‘password’] . “
”;
echo "password MD5 : " . $password . "
";

// Print login failure message to the user and link them back to your login page
print ‘

No match in our records, try again


Click here to go back to the login page.’;
exit();
}
[/php]

Now, you will see that this added code will show you what the user is typing in and what the code is converting it to. You can then see if the values your program is checking for is what is inside the DB.

That is the first step. Make sure the values match. In your registration page, you need to make sure it is using the same MD5 setup for the password, too.

So, make that change, test the page and look up the values in the DB and compare them. Hope that solves it! Good luck…

www.webdesigngroup1999.com/memberSystemBasic/login.php This is what I am getting.

Well, that is your problem. It is not pulling the info from the posting page.

You are getting nothing to the page.

Okay, I found it. Sorry, I looked right over it. You are checking the POST for ‘email’ not the name of the submit button. So, change this line:

[php]
if ($_POST[‘email’]) {
[/php]

To
[php]
if(isset($_POST[‘Submit’])){
[/php]

You were checking for the email to be submitted, you really need to check for the submit button to be pressed and getting by the validation. This new line check to make sure the submission went thru.

Sorry I didn’t see that at first…

Still problem with log in page.Same thing.

So, what did you get for outputs from the other lines I put in?

Got errors

Well, what exactly is it doing? Is it going somewhere else? Can you show us your current code?
" Got errors " doesn’t help us… What errors? Show your code again and tell us where you get the errors and what the errors is and we can help!

Help us help you… I am sure it is something small as most of your code looks correct…

Yes you can help, do you have some tutorial for register and log in page which will work 100%,with code and videos how to do it.

There are thousands of login script tutorials on the web. You should trust your buddy, Google for these.
Just make sure that you use the correct search words. For instance, you should start the words with something like “php login script tutorial” or whatever…

Here are a few that I found in about 30 seconds with Google… Hope they help explain the steps for you!

http://www.phpeasystep.com/phptu/6.html
http://php.about.com/od/finishedphp1/ss/php_login_code.htm (Seven short steps.)
http://phpcollection.com/php-login-system-login-management-and-login-control-tutorial/

A bit more advanced tutorial…
http://tutorialzine.com/2009/10/cool-login-system-php-jquery/

This one is much more advanced and uses a lot of classes. But, it contains a lot of info about user permissions and roles. Advanced learning items.
http://net.tutsplus.com/tutorials/php/a-better-login-system/

Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service