LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2015, 11:29 AM   #1
fred2014
Member
 
Registered: Mar 2015
Posts: 70

Rep: Reputation: Disabled
repopulating HTML variables after history(-1) from $_POST with PHP


Developing a web page on windows using apache-php I can send a history -1 (back a page) via PHP/jscript and a form will re-populate its variables

However when I upload the same code/page to my centos server (same apache php etc)the variables don't get re-instated. i.e. the form is empty again.

The form uses the POST method so presumably the contents still exist in that
but I'm not very familiar with javascript or why this only works automatically on windows.

can anyone tell me the simplest way to get this form repopulated on a centos/apache server please?
 
Old 03-10-2015, 07:22 AM   #2
fred2014
Member
 
Registered: Mar 2015
Posts: 70

Original Poster
Rep: Reputation: Disabled
anyone - any ideas?
 
Old 03-10-2015, 07:40 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

How does that PHP page look like? In old versions of PHP, things sent with POST or GET were assigned as global variables. There was a "register_globals" setting you could set in php.ini, but in new versions, it's been dropped.

If your PHP is a bit old, you turn on register_globals in php.ini. But if it's 5.4 or newer, you have to fix the code.

For example change a line like this:

PHP Code:
<input type="text" name="username" value="<?php echo $username?>">
Into this:

PHP Code:
<input type="text" name="username" value="<?php echo htmlspecialchars($_POST['username']); ?>">
 
Old 03-10-2015, 09:32 AM   #4
fred2014
Member
 
Registered: Mar 2015
Posts: 70

Original Poster
Rep: Reputation: Disabled
thanks guttorm

I'm familiar with $_POST in php - If I understand correctly all I need do is your suggested changes and rename the HTML file to PHP.
(I've never really used javascript as such hence my uncertainty)
I will give that a go.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP - POST variables named with counter: $_POST[${"variable$counter"} winairmvs Programming 1 08-06-2010 04:56 PM
PHP Mystery POST and GET variables without $_POST[] and $_GET[] action_owl Programming 1 05-18-2010 05:38 PM
changing contents of $_POST in PHP jiml8 Programming 2 04-04-2006 09:11 AM
PHP : $_POST['choice$i'] doesnt work WindowsBurner Programming 7 12-18-2004 08:06 AM
PHP:Unable to post variables from html form to mysql database vikram_cvk Linux - Software 1 09-29-2004 03:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration