Pages: 12Next
Current Page: 1 of 2
Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 02, 2008 11:14PM

Hi everybody smiling smiley I have a problem using $_POST on my wamp smiling smiley

I until recently uploaded all my code to a FTP to a professional hosting company server. It was great for my needs.

Then I heard about wamp, and it seems to be a almost perfect solution. But it seems that my offline code had some problems using $_POST. When I tried to call print_r($_POST); it was totally empyt, while online it was correctly filled..

Now, what do I do, to make it work? smiling smiley I expect it to be something in the .ini file, but i'm not sure.. Please have in mind that I do not have that much experience yet.

btw, the search on this site doesn't seem to work for me?

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 02, 2008 11:37PM

print_r($_POST);


this isnt not correct php

u need a varaible???



anyway proper way to write this is

$xxxx=$_POST['xxxx']'
print_r($xxxx);



fill in xxxx as yout variable being posted

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 02, 2008 11:49PM

I am sorry to inform you that it does work, on my offline version $_POST is empty, on my online version the $_POST contains the info that is needed.

code:
echo "<pre>";
print_r($_POST);
echo "</pre>";

result - offline:
Array
(
)

result- online:
Array
(
[username] => admin
[password] => password
[loginremem] => on
)

smiling smiley

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 02, 2008 11:52PM

well its wrong.

you need to use $_POST with a variable..

you should not just assume it will know wat to print.


paste up both form and php script.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 02, 2008 11:57PM

The script works fine, its running on proffesional paid for company servers, with no problems at all. smiling smiley

The problem is that my WAMP server does not give the $_POST variables to the script.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: March 02, 2008 11:59PM

You have to enable Output_Buffering in php.ini file in apache/bin directory.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 03, 2008 12:00AM

im not saying your way of doing things wont work.. but u dont do it unless you wanna justcheck the array being past.



there is no problem with $_POST on wamp

there is a prolem with your script


so post the whole thing up if you want it checked

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 03, 2008 12:07AM

no output buffering is enabled by default on wamp, jixar just post the script up if you want it checked.
dont mind that it works on other server



Edited 1 time(s). Last edit at 03/03/2008 12:09AM by stevenmartin99.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 03, 2008 12:13AM

stevenmartin99 => I do not want it checked. I'm not saying wamp is buggy either. I belive it is a simple server setting that does the trick. I have checked and double checked, even with the solution you suggested (print_r($_POST['xxx'])winking smiley

Following line returns a false, and displays the default error for empty pass/user:
Validator::login($_POST['username'], $_POST['password']);

Inside the code there are several checks wehter the pass/user is either empty, or invalid (' OR ''='' is invalid ;-) ) They return a false on the local, because the variables are empy. While online the script works fine.

- Now, please take your eyes of the code.

hambuler => output_buffering = on

It doesn't do the trick? smiling smiley



Edited 1 time(s). Last edit at 03/03/2008 12:19AM by Jixar.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 03, 2008 12:19AM

people on this site looking for help get more rude every day..


if your POSTING A VARIABLE WITH THE NAME password TO A PHP SCRIPT


AND YOU HAVE


<?php
$password=$POST['password'];

echo $password;
?>


IT HAS TO WORK
THERE IS NO "LITTLE SETTING" TO MAKE IT WORK
YOUR CODE IS WRONG..

Options: ReplyQuote
Re: Problem with $_POST
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: March 03, 2008 12:26AM

I forget to tell you you have to enable register_globals in apach2/bin php.ini file. It's not advisable to leave it on forever.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 03, 2008 12:28AM

this was taken out of php5.2 for a reason...

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 03, 2008 12:37AM

register_globals = on
No effect smiling smiley

And stevemarting99, no need to write in caps, nobody is rude smiling smiley

Remember that we're all trying to solve the problem.


Is it possible that local settings for Javascript might do the difference? I'm using Firefox..

Relevant JS code + html:

function loginFormSubmit(sentForm)
{
if(sentForm.loginremem.checked&&!loginFormUnTouched)
setLoginCookie(sentForm.username.value,sentForm.password.value);
document.cookie="logget=true;expires=";
sentForm.submit();
}

<form name="loginform" style="padding:0px;margin:0px;" action="<?php echo $url->setVar("action", "logon"winking smiley; ?>" method="post">
<?php $url->remVar("action"winking smiley; ?>
<input type="text" name="username" style="width:120px;" onKeyDown="loginTouched()"><br>
<input type="password" name="password" style="width:100px;margin-top:4px;margin-bottom:4px;" onKeyDown="loginTouched()"><br>
<input type="checkbox" name="loginremem" onClick="if(this.checked){if(!confirm('Vil du have computeren til at huske dit login næste gang du kommer på?')){this.checked=false}}">Husk mig<br>
<input type="button" name="loginbutton" value="Login" onClick="loginFormSubmit(this.form)"><br>
</form>

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 03, 2008 12:41AM

action="<?php echo $url->setVar("action", "logon"winking smiley; ?>"



wat is this?


do you have another script? that prints them


cos it shoud be
action='otherscrotname.php'


your no even passing the variables onto the oter page thats why they are blank

Options: ReplyQuote
Re: Problem with $_POST
Posted by: hambuler (---.cpe.net.cable.rogers.com)
Date: March 03, 2008 12:42AM

Quote:
register_globals = on
No effect smiling smiley
****************

Have you restarted the apache server?

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 03, 2008 12:49AM

hambuler => Server was restarded, 3 times to make sure smiling smiley
Remote server is running globals off.

Stevemartin99 => its my URL object, the method setVar($keyword, $value); adds and returns an url ex:

$url = new URL("forum.wampserver.com/read.php"winking smiley;
$url->setVar("action", "logon"winking smiley; //forum.wampserver.com/read.php?action=logon

If you use it again, it adds even more smiling smiley

$url->setVar("thread", "1258"winking smiley; //forum.wampserver.com/read.php?action=logon&thread=1258

Its how I controll the links on the entire page smiling smiley



Edited 1 time(s). Last edit at 03/03/2008 12:51AM by Jixar.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: March 03, 2008 12:53AM

if its in the url


u need to use GET not POST

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 03, 2008 12:57AM

The variables from the forms are in POST.

The action defines where you are taken when you submitted the login

action='index.php?action=logon' method='POST'

^takes you to 'index.php?action=logon' with both GET and POST's

It does work smiling smiley this page uses it to make sure you land on the english site when submitting.

Options: ReplyQuote
Re: Problem with $_POST
Posted by: yfastud (Moderator)
Date: March 03, 2008 01:36AM

Jixar
I know you don't like to post the whole codes since it's a little personal, but it would not help if you keep post piece by piece. If you really like to get your problem solve, you might edit to replace all personal info and post your whole script so people can help you out
BTW, mots hosting services out there are *nix which might have a little different settings compare w/ wamp, so if your scripts run perfectly on your host service, ask your host's tech what need to be done in order for you to test your script on local wamp (Apache, MySQL, and PHP run on Windows)

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Problem with $_POST
Posted by: Jixar (---.ds1-od.adsl.cybercity.dk)
Date: March 03, 2008 09:11AM

The code is not that personal, its shared by 4 students i study with, its just a bit complex.. I have simplified it a bit here then:

SIMPLE index.php:
<?php
	
	include_once("core/core.php"winking smiley; //Class files, db connection, etc.
	//Also includes ActionHandler.php!
	
	include_once("plugin/PluginHandler.php"winking smiley; //Plugin handling, decides what page to show.

//Design is added...

	echo Menu::writeUserMenu();	//This static method adds the menu for the current user, this is where the problems are...

//More design

?>
SIMPLE Menu class:
<?php 
	$currentUser = new CurrentUser();	//This class tells the script who the user is, userlevel, id, name and the most important, is he logged in??

	if($currentUser->isOnline()){ //Is the user logged in the system.
		//Design and the menu for the user.
	}else{
	?>
		<fieldset style="padding:5px;">
		<legend>Login her&nbsp;</legend>									
			<form name="loginform" style="padding:0px;margin:0px;" action="<?php echo $url->setVar("action", "logon"winking smiley; ?>" method="post">
																		<?php $url->remVar("action"winking smiley; ?>
			<input type="text" name="username" style="width:120px;" onKeyDown="loginTouched()"><br>
			<input type="password" name="password" style="width:100px;margin-top:4px;margin-bottom:4px;" onKeyDown="loginTouched()"><br>
			<input type="checkbox" name="loginremem" onClick="if(this.checked){if(!confirm('DO you want the computer to remember you next time you enter the page?')){this.checked=false}}">Cookie <br>
			<input type="button" name="loginbutton" value="Login" onClick="loginFormSubmit(this.form)"><br>
			</form>
		</fieldset>
	<?php 		
	}

SIMPLE ActionHandler.php
<?php
	$action = $_GET['action'];
	if($action == "logon"winking smiley{	//Brugeren forsøges logget ind
		Validator::login($_POST['username'], $_POST['password']);	//Logs user in, return bool and mutate a class that writes a message for the user in the design.
		
		$currentURL = new CurrentURL();	//Contains the URL of the current page, contained in arrays.
		$currentURL->remVar("action"winking smiley;
		Validator::redirect($currentURL->getUrl());	//A redirect function, since the actionhandler is included in core.php, it can be done via header.
	}
?>

Javascript for loginForm:
function loginFormSubmit(sentForm)
{
	if(sentForm.loginremem.checked&&!loginFormUnTouched)
		setLoginCookie(sentForm.username.value,sentForm.password.value);
	document.cookie="logget=true;expires=";
	sentForm.submit();
}
SIMPLE class Validator
<?php
	public static function login($username, $password){
		if(($legal) && (!isset($password))){$legal = false;}
		if(($legal) && (!isset($username))){$legal = false;}
		if(($legal) && (!Validator::validUsername($username))){$legal = false;}
		if(($legal) && (!Validator::validPassword($password))){$legal = false;}
		if($legal){
			$encryptedPass = Validator::spicyPassword($password);	//Add a salt and encrypt
		}

		if($legal){	//User exists?
			$num_usernamesPasswords = DB::sqlNum("SELECT id FROM users WHERE username='$username' AND password='$encryptedPass'"winking smiley;
			if($num_usernamesPasswords != 1){
				$legal = false;
			}
		}
			//Log user in
			//Return true.
		//If user not logged in return false
	}
}
?>

I can't see where the code should be wrong. Everything with login except the forms, happen before headers are sent to the user.

It uses $_POST to login and nothing fancy beyond that.
The javascript simply places a cookie on the machine and submits the form.

EDIT: Typo's and ekstra text smiling smiley



Edited 2 time(s). Last edit at 03/03/2008 09:23AM by Jixar.

Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


Sorry, only registered users may post in this forum.