PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Before I start rambling, I'm running an OpenBSD web server using Apache and PHP 4.
All I want is a login system where the users type in any name they want and a pre-specified password in "index.php" and it takes them to "terminal.php" and uses their user name that they specified in that page. However, it shouldn't take them to the terminal.php if the password is wrong and they shouldn't be able to access terminal.php without logging in first. I figured that the easiest way to do this is with php sessions, but so far no dice.
When I hit login all I get is a blank page. Please excuse my messy and amature coding! I would *really* appreciate if someone would sift through it with me and tell me what I'm messing up on. Thanks!
A few things:
I wouldn't use session_register as it is deprecated I believe. Use the $_SESSION superglobal . Then you can use it just like any other array value:
function redirect($page)
{
if(!headers_sent()){
header('Location: http://www.yourdomain.com/' . $page);
exit;
}
echo "headers were already sent, so we can not redirect... sorry";
}
Sorry for making so many posts, but I think Ihave it figured out except for this one thing
Parse error: parse error, unexpected $ in /htdocs/site/terminal.php on line 35
Line 35 is blank. I read up on this on the internet and apparently this is due to a file corruption on upload. I'm uploading it via SSH using WinSCP (I tried the puTTY ftp-clone too) and I've tried deleting and re-creating the file. Nothing works.
PHP commonly reports an error on a line before or after the line with the actual error. It happens to me all the time.
Just look near where it says the error is, nothing is perfect
I really doubt your files are corrupted on upload, it's very uncommon. And I've had my share of crappy internet connections
St8ic wrote:Sorry for making so many posts, but I think Ihave it figured out except for this one thing
Parse error: parse error, unexpected $ in /htdocs/site/terminal.php on line 35
Line 35 is blank. I read up on this on the internet and apparently this is due to a file corruption on upload. I'm uploading it via SSH using WinSCP (I tried the puTTY ftp-clone too) and I've tried deleting and re-creating the file. Nothing works.
Has anyone else had this problem?
Look for missing curly braces or missing semi-colons.
It does a redirect, for example if you wish to send a user to another page. Now if you are asking about full url's, I never bother It works fine for me...
Last edited by toasty2 on Sun Sep 03, 2006 2:58 pm, edited 2 times in total.
function redirect($page)
{
if(!headers_sent()){
header('Location: http://www.yourdomain.com/' . $page);
exit;
}
echo "headers were already sent, so we can not redirect... sorry";
}
Is it actually possible to do this? Or at least i haven't been able to get it to work. It seems that the $page variable is unable to be passed though/ to the function. Doing so seems to result in any dots getting "lost".
For example, calling... redirect(index.php) atempts to redirect to http://example.com/indexphp NOTE: the missing dot
You should test your scripts with error_reporting=E_ALL and either display_errors or keeping an eye on your webserver's error log.
You can set those values within the script if you must
error_reporting(E_ALL); ini_set('display_errors', true);
function redirect($page)
{
if(!headers_sent()){
header('Location: http://www.yourdomain.com/' . $page);
exit;
}
echo "headers were already sent, so we can not redirect... sorry";
}
but it's better to set them e.g. in the php.ini on your test webserver.
String literals have to be marked for php or they are considered constants. In this case as two constants concatenated by .
Note the double quotes (also works with single quotes).
If you leave the quotes out, php sees an undefined constant called index and an undefined constant called php, and sees that they are concatenated with the full stop (period). Since you haven't defined constants index and php, the php engine decides to define them itself. Result is that you get "indexphp".