GetDotted Domains

Viewing Thread:
"Quicky PHP question"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Wed 12/03/03 at 00:39
Regular
Posts: 787
I've asked this before, but can't find the topic.

I've just formated my Hard Drive, and installed all the things I have to run a Server on my machine, for testing sites and scripts, etc.

The problem now is PHP doesn't pass Variabes from page to page, so submiting forms or adding them onto the ends of addresses doesn't work anymore, and I'd like to know what I have to change to allow this to work again.

I know it's something in the PHP.ini file, but I can't remember which item I'm supposed to alter in order to make the Variables work.

Thanks in advance for anyone who can jog my memory :)
Mon 17/03/03 at 07:59
Regular
"Eff, you see, kay?"
Posts: 14,156
You're using the wrong functions I think. Try fread() instead of fgets().
Mon 17/03/03 at 01:04
Regular
"It goes so quickly"
Posts: 4,083
Me again, with a Whitespace problem :(

When writing data which contaings carrage returns from a Form into a text file, there is no problem. The data is from a textarea input.

When PHP tries reading the file and displaying it however, it cuts off as soon as it gets to the end of the first line, and I would prefer it to read the whole file.

$fp = fopen("$File", 'r') or die("ERROR:");
flock($fp, 1);
$Data = fgets($fp, filesize($File) + 1);
flock($fp, 3);
fclose($fp);

Would anyone know of a simple solution around this little glitch in my code??

Thanks :)
Thu 13/03/03 at 12:14
Regular
"It goes so quickly"
Posts: 4,083
The Script is basically an Error Log system for a friend Web Site. Somone can fill in a Form to report an Error, and its saved in a Text File, which is then accessed by the index.php script to list each error in its own Table layout.

Each table has a 'Report Error as fixed' link, which is for my friend to when she has fixed the reported bug, so she knows that bug has been corrected.

The link takes her to Error_Fixed.php?ID=1, with the ID refering to which error it is that's being reported fixed. Now, this part of the script works fine, well it did until I added the login area.

session_start();
if (file_exists("Authorise.php"))
include("Authorise.php");
else
die("

Unable to Authorise you, due to a required file missing

");

$User = Verify("$Details[Username]", "$Details[Password]");
if (! $User) {
header("Location: Login.php?Target=Error_Fixed.php?ID=$ID");
exit;
}

Was the original code, and you'll see the $Details[] bit is the actual array from the Seesion.

However, I also used $Details as an array for the bits of data for each Error report, $Details[0], $Details[1], etc, which caued confusion in the script, and so I changed the Seesion Variable from $Details to $Session ...... and all it was, I forgot to change that in the code above

$User = Verify("$Details[Username]", "$Details[Password]");
.. to ..
$User = Verify("$Session[Username]", "$Session[Password]");

... and everything works as normal. I was complrtly looking into the wrong area, as if you look at the script at the top, because the $Session[] wasn't in the Verify function, it was always going to return false, and therefor send me back to the Login page every time.

I feel very stupid .... but thank you for taking the time to look into it everyone. It just goes to show that there is geeraly a simple reason for something not to work.

:) thanks again, and sorry for the bother.
Thu 13/03/03 at 08:50
Regular
"Devil in disguise"
Posts: 3,151
Hm, just copied your code into a couple of files and ran it. I only encountered 1 problem with it though. I got the header info already sent error, but that disappeared when I removed some whitespace from the end of authorize.php. Other than that if I put:

http://localhost/login.php?actionflag=Login& Username=Username1&Password=Password1&Target=user.php

It behaved as the code intended (as far as I can see), ie it redirects to user.php.
Thu 13/03/03 at 07:55
Regular
"Eff, you see, kay?"
Posts: 14,156
I agree with the suggestions. Are you sure
Thu 13/03/03 at 02:56
Posts: 0
My guess would be that calling the session functions, and/or including another *.php file could be causing headers to be sent before you expect.

I would try putting in some debug code using the 'headers_sent()' function to determine where the headers actually are sent.

If you can't get the script to work the way you wish, then you may have to look in to using output buffering with the ob_* functions to control exactly when the headers are sent.

But even they may just cause all the output to be cached and the headers could still end up being sent before you expect/want!
Thu 13/03/03 at 00:35
Regular
"It goes so quickly"
Posts: 4,083
Not that I can see:

session_start();
session_register("Session");

if (file_exists("Authorise.php"))
include("Authorise.php");
else
die("ERROR: Unable to connect to the require infomation to log you in.");

if (isset($actionflag) && $actionflag == "Login") {
$Username = trim($Username);
$Password = trim($Password);
$Target = trim($Target);
$User = Verify("$Username", "$Password");

if ($User) {
$Session[Username] = $Username;
$Session[Password] = $Password;
$Session[Loggedin] = true;

if ($Target)
header("Location:$Target");
else
header("Location:index.php");

} else {
$Error = "Username and Password incorrect.";
}

}
?>

Is the code I have, and in the Authorise.php is :

function Verify($Username, $Password) {
$Usernames = array("Username1","Username2");
$Passwords = array("Password1","Password2");

$Counter = (integer) 0;

foreach ($Usernames as $Temp) {
if (("$Temp" == "$Username") && ("$Password" == "$Passwords[$Counter]"))
$Accept = "1";
$Counter++;
}
if ($Accept == "1")
return true;
else
return false;
}
?>


The Scripts are just a simple Login Site, which if your details aren't saved in the session, you're taken to the login page and have to log in. Then your Username and Password are checked to match the entries in the arays, and your details saved to the session, and you move on.

The problem is, rather than moving on, the Login.php page is just reloaded as if it ws the first time the user went to it.

Any ideas of the errors in the code??

Thanks
Thu 13/03/03 at 00:23
Regular
"Eff, you see, kay?"
Posts: 14,156
Have you got whitespace in there by accident? Is anything producing an error above the headers somewhere?
Wed 12/03/03 at 21:35
Regular
"It goes so quickly"
Posts: 4,083
I'm now having a few problems with the header(Location); function.

The Script first told me that the headers had already been sent, but I'm not sure what part of the script is doing that. I was under the impression that if you put the header() before having any ouput writen to the browser you were ok to use it.

I altered a few things, and now I don't get the warning that headers have been sent, but the script still ignores the header("Location:"); command.

Any ideas as to why this maybe the case????
Wed 12/03/03 at 19:23
Regular
"Eff, you see, kay?"
Posts: 14,156
No problem.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Excellent
Excellent communication, polite and courteous staff - I was dealt with professionally. 10/10
Easy and free service!
I think it's fab that you provide an easy-to-follow service, and even better that it's free...!
Cerrie

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.