Page 1 of 1

PHP newbie question

Posted: Tue Dec 09, 2003 1:22 am
by concatenate_man
Hi, I am a newbie to PHP (trying to teach myself) and I apologise in advance for what may seem like a dumb question. I am having trouble getting my code working after authorisation is successful. what i am trying to do is to get my test.php file to call/display another php file from the success block of code. here is the code if it helps

Code: Select all

<?php

$username = $_POST&#1111;'username']; 
$password = $_POST&#1111;'password']; 

$connection = @mysql_connect(****,****,****);

$db = @mysql_select_db(*****, $connection);

$sql = "SELECT * FROM members WHERE username = '$username'";
$result = mysql_query ($sql);
$row = mysql_fetch_array($result);

$usercheck = $row&#1111;"username"];
$passcheck = $row&#1111;"password"];

if ($passcheck == $password and $usercheck == $username and $username != ""):


$_SESSION&#1111;'authenticated'] = "yes";
$_SESSION&#1111;'error'] = "no";
here is where I have the problem I have used this script in the double quotes as it is the only one I have found so far but it gives me a directory listing and wont let me go to another php page

Code: Select all

"header("Location: http://".$_SERVER&#1111;'HTTP_HOST'].dirname($_SERVER&#1111;'PHP_SELF'])."/". $_SESSION&#1111;"sourcepage"]); " 

else:

echo ("You do not have authorization to enter. Please contact admin to register.");

endif;

?>
I am confused a bit as I have only just started to teach myself PHP and I don't have any programming experience.

Thanks,
concatenate_man

Posted: Tue Dec 09, 2003 1:45 am
by microthick
Your login script will only authenticate successfully if you have only 1 user in your database, or the first row selected from the db matches your form login and password, btw.

I didn't totally get your last part.

If you want to redirect to another page, just go:

header("Location: http://www.yoursite.com/yourpage.php");

Posted: Tue Dec 09, 2003 2:04 am
by concatenate_man
If you want to redirect to another page, just go:

header("Location: http://www.yoursite.com/yourpage.php");
Thanks for answering, although I want to redirect from the same directory I am in, eg i have a enter.php file where the user logs in, a test.php file that checks authentication and then in that test.php file when authoristaion is successful i want it to redirect to marcat.php file that are all in the same directory.

does that make any sense :?:
cheers
Joe

Posted: Tue Dec 09, 2003 2:10 am
by infolock

Posted: Tue Dec 09, 2003 2:17 am
by concatenate_man
Ok i have done that but my computer freezes when it tries to open test.php

cheers
joe

Posted: Tue Dec 09, 2003 2:44 am
by concatenate_man
Hi, when i use these two code lines

Code: Select all

//header("Location: http://localhost/marcat/marcat.php");
header("Location: C:/Program Files/Apache Group/Apache/htdocs/marcat/marcat.php");
this one works

Code: Select all

header("Location: C:/Program Files/Apache Group/Apache/htdocs/marcat/marcat.php");
and this one doesn't

Code: Select all

header("Location: http://localhost/marcat/marcat.php");
cheers
Joe

Your code

Posted: Tue Dec 09, 2003 2:25 pm
by dbudde
The second line of code does work for me if I use the server's actual IP address and not just LOCALHOST just so you know.