Jump to content

redirected to a website for no reason


freddyw

Recommended Posts

okay. So i had another topic. Ive changed my code and scrapped it.

 

(will tick that topic as solved in a second)

 

I got this code off a website. It seems to be working. However... its not taking me to protected.php like it should.

 

heres my code

<?
session_start(); //initialize session mechanism

if(!isset($_POST['ok'])) {
// if the form is not completed, display it
    echo"
    <html>
    <head>
    <title>Authorization page</title>
    </head>
    <body>
    <table width='100%' height='100%'>
    <form method='POST' action='login.php'>
    <tr><td align=center>
    <table>
    <tr><td>
    <table>
    <tr><td>Login:</td><td><input type='text'
        name='login' size='15'></td></tr>
    <tr><td>Password:</td><td><input
        type='password' name='pass' size='15'></td></tr>
    </table>
    </td></tr>
    <tr><td align=center><input type='submit' name='ok'
        value='Enter'></td></tr>
    </table>
    </td></tr>
    </form>
    </table>
    </body>
    </html>
    ";
}
else{    
    //supposed that user data
    //is saved in database, in users table, that includes id, login, pass fields

    $db=mysql_pconnect('sql201.byethost11.com', '********', '********') or die(mysql_error());
    mysql_select_db('b11_4059953_db1', $db) or die(mysql_error());
    
    //check if there is a user with such login and password
    $res=mysql_query("SELECT * FROM user WHERE username='".$_POST['username']."'
        AND password='".$_POST['password']."'", $db);
    if(mysql_num_rows($res)!=1){    //such user doesn’t exist
        echo "Incorrect login and password";
    }
    else{    //user is found
        $_SESSION['login']=$_POST['login'];    //set login & pass
        $_SESSION['pass']=$_POST['pass'];
        header("Location: protected.php");    // redirect him to protected.php
    }
    
    mysql_close();
}
?>

 

its taking me to another website, whether the log in is correct or not.

 

you view it here as the site is live

 

http://fredundant.byethost11.com/log.php

 

 

username: php

password: freak

 

 

 

any ideas why its going to that website?

Link to comment
Share on other sites

thanks tom.

but hasn't made a difference

 

Hmm, where exactly is it redirecting? or is it just not redirecting at all?

 

If you got the page name wrong and if you are using a free host they dont normally take you to a 404 error and instead a random page with ads.

Link to comment
Share on other sites

look at it for yourself

 

 

http://fredundant.byethost11.com/log.php

 

log in with username: php and password: freak

 

it should go here

 

 

http://fredundant.byethost11.com/protected.php

 

Hmm unfortunatly i just cant get off the login to even see protected.php 

 

So i cant help you any more, ill read over your code and if i can help ill post but at the moment i cant sorry.

 

Yep the page p

Link to comment
Share on other sites

ive edited the original code. I had careless mistakes.

 

the code is now

<?
session_start(); //initialize session mechanism

if(!isset($_POST['ok'])) {
// if the form is not completed, display it
    echo"
    <html>
    <head>
    <title>Authorization page</title>
    </head>
    <body>
    <table width='100%' height='100%'>
    <form method='POST' action='log.php'>
    <tr><td align=center>
    <table>
    <tr><td>
    <table>
    <tr><td>Login:</td><td><input type='text'
        name='username' size='15'></td></tr>
    <tr><td>Password:</td><td><input
        type='password' name='password' size='15'></td></tr>
    </table>
    </td></tr>
    <tr><td align=center><input type='submit' name='ok'
        value='Enter'></td></tr>
    </table>
    </td></tr>
    </form>
    </table>
    </body>
    </html>
    ";
}
else{    
    //supposed that user data
    //is saved in database, in users table, that includes id, login, pass fields

    $db=mysql_pconnect('sql201.byethost11.com', '********', '********') or die(mysql_error());
    mysql_select_db('b11_4059953_db1', $db) or die(mysql_error());
    
    //check if there is a user with such login and password
    $res=mysql_query("SELECT * FROM user WHERE username='".$_POST['username']."'
        AND password='".$_POST['password']."'", $db);
    if(mysql_num_rows($res)!=1){    //such user doesn’t exist
        echo "Incorrect login and password";
    }
    else{    //user is found
        $_SESSION['username']=$_POST['username'];    //set login & pass
        $_SESSION['password']=$_POST['password'];
        header("Location: protected.php");    // redirect him to protected.php
    }
    
    mysql_close();
}
?>

 

so now if a username and password are entered the page resets itself. and if an incorrect username and pass are entered it echo's as it should.

 

any ideas?

Link to comment
Share on other sites

ur form action is going to login.php and you have written the code in log.php, try posting the form to log.php

 

Thanks sam i noticed that. Along with a few other mistakes. try logging in for me with any username you want. then try again with php and freak.

 

can see why that is happenning?

 

 

As this is a new problem, does it require a new topic. I just dont want to hog the board too much

Link to comment
Share on other sites



session_start();
//this checks to see if the $_SESSION variable has been not set 
//or if the $_SESSION variable has been not set to true
//and if one or the other is not set then the user gets
//sent to the login page
if(!isset($_SESSION) || $_SESSION !== true){
header('Location: log.php');
}


echo "You are currently logged in";  


echo "welcome";

?>

Link to comment
Share on other sites



session_start();
//this checks to see if the $_SESSION variable has been not set 
//or if the $_SESSION variable has been not set to true
//and if one or the other is not set then the user gets
//sent to the login page
if(!isset($_SESSION) || $_SESSION != true){
header('Location: log.php');
}


echo "You are currently logged in";  


echo "welcome";

?>

 

Ok i just cahnged your code, as ive never seen !==  (is that meant to be there? ) try the code in the code box above

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.