Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to generate webpages dynamically.for example I have a website called abc.com in which I have included a form with many fields.
When a user submit this form,I want a new webpage abc.com/xyz to be created.Wondering if this is possible.
Of course it's possible. Anything is possible in programming/development.
See the following PHP manual for a good tutorial: http://www.php.net/manual/en/domdocument.savehtmlfile.php
This is possible in variety of ways.
You can pass GET variables in URL (example.com/page?var1=1&var2=2) and use this variables to generate unique page by predefined template.
If you don't want to use variables in URL, you can POST them to page via form request or ajax call.
Alternatively you can use .htaccess configuration files to rewrite your URL and use url segments as variables (example.com/var1/var2), this is common approach in MVC systems, where first/second variables are class/method names.
So here's an example:
You have a page.php where form resides.
User fills a form and submits it.
Form goes trough AJAX call, submitting it to request.php page
request.php parses it and stores it in DB, generating unique id
AJAX event recieves from request.php a unique id and redirects user to review.php
with url (example.com/review/uniqueID) or (example.com/review.php?uniqueID)
review.php recieves uniqueId, get's info from DB by it and displays requested info
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to protect my PHP files from direct access, but my problem is that i do not include them in my index. I use jquery load() or iframe, so basicly the php files in include folder don't have access or code from index.php. So i tried with define CONST, but of course didn't work... So basicly i have URL site.com/file witch i load in my index with jquery load as a pop up, but i don\t want if someone try to access it directly from browser to have access... Any idea how should i protect them?
Mike's answer works for regular users, but if you need to be sure that the user first loads the index page, you could do something like:
generate a token when user loads index.php
add token to session data
add token to jquery load as a query parameter (e.g. site.com/file?token=xxxx)
on file load, compare token passed as parameter to the one stored in session and clear the session, so it cannot reuse the token
This way, the user is required to load index.php before loading file.
It wouldn't prevent an advanced user from acessing the file page directly after having the token.
try this, first block limits access to ajax requests, second one checks referring url is mywebsite
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
echo "<span class='error_msgh'>Error 1. Process Aborted.</span>";
die();
}elseif(!preg_match('/(www.mywebsite.com)/', $_SERVER['HTTP_REFERER'])){
echo "<span class='error_msgh'>Error 2. Process Aborted.</span>";
die();
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm doing a web app with PHP in which users have different number of tabs in the menu depending on a certain number of things, one user can have one tab in the menu where another user has ten.
I've managed to dynamically generate the menu items but now I don't know how to create files (pages) where the user gets redirected once he presses on any of the menu tabs.
All these files look the same the only thing that changes are the text, just some strings.
Summing up, what I want to do is:
Generate and destroy files automatically when the user has to consult something
How to link the menu tabs (href) to them automatically
The best would be to use a PHP page as template you could call it.
Lets say for example a user is logged in and clicks the view data page (data.php)
on your link you could have something like this:
and in data.php:
<?php
$USER_ID = htmlspecialchars($_GET["id"])
//SQL Request to get user priviledge and authentificate
//OR
//Check the cookie session for information
if (user_priviledge == 0)
{
//
//Show only data for 0 users
//
}elseif (user_priviledge == 1) {
//
//Show only data for 1 users
//
}
?>
This may not be the solution you wanted but your question wasn't very clear either so if you need any other information make sure to bring more precision.
The condition which are using for tab use same condition to show page. But add that condition in your text.Because your text is changing not page I think.
I this this might help you.
since all files will look the same and only variables will change, you can create one php file and just send the necessary data when a user clicks on the tab to assign to the variables in that page. You do not need to keep on creating custom pages for each and every tab.
Provide some code which you have written for this so that we can help you further
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to check if any data in a form has been changed by a user, either removed, added or modified in any way and send the data to PHP so that I only have to execute specific update commands instead of updating everything. What's the best way of doing this?
First decide do you need to check updated data in client side or server side.
If you check updated data in client side, you will prevent submit unwanted data and submit will be quick.
To achieve this, when you submitting form before submit, in following js method check which data has changed. First in document ready function, create hidden variables or global js variables and assign initial values of form. Then in following method check current form values with those variables values. Then you can identified which data has been changed. Then from form remove existing values.( You may be need to aware of mandatory fields when remove data).
$("#myform").submit(function(){
// Put code here.
});
If you are planning to check data in server side, you can place logic in server side and prevent be messing client side code and store heavy data. To achieve this you have to do extra database call. After get data from form, in server side do extra db call which use to initially load data to form and check what are the changed data and then save only updated data.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Similar to how you create a post in wordpress or even ask a question on this very website.
I want to know how to create a page by just filling out a form?
Here's what I know:
-I know how to make an html form
-I know how to place data in a database and take it out
-I know some php
What I don't know is how to to tie all of these things together. Please be as specific as possible and if you know of a tutorial on how to do this or you have the time to make a small example I would be very very grateful.
Thank you in advance for your time :-)
EDIT: To provide more details
I want to send data from a form (even a few text inputs would be enough) and for them to be placed in a page where I can display them.
And also that page should have an unique identifier so it gets stored similar to the questions on stack overflow where there is www.stackoverflow.com/posts/'identifiernumber'
And I would always to go back to that information provided I access the link which I assumed will be stored in the database.
Wordpress uses wysiwyg this is used to convert normal text into html code you can find jquery plugins for it.After user has entered the content of the page and hits submit. Wordpress directly stores the content in the database in HTML FORMAT . Now all it does is echo out the content stored in the database.
Now for the identifier , it should point out to the primary key of the database row where the content is stored. Wordpress stores a unique url as the identifier like the questions you asked is How to create a page using a form? php/html it will store it as how-to-create-a-page-using-a-form-php-html . This is then put in the href attribute of <a> tag , on click of this unique identifier it echo out the content of that row.
All you have to do now is make a form and textarea , apply the wysiwyg plugin on the textarea . Then onsubmit store the data in the database and also creating a unique identifier for it.
You question now is how to pass the identifier in the URL?
First you must know how to pass a variable in the URL and then capture it in the required place eg : www.yourwebsite.com?identifier=something and to make this a link on you website
Something
Once you have mastered this you can then study a concept called MOD REWRITE and in layman term for this is called clean URL or SEO URL . There are many blogs and methods of achieving this goal. You can google MOD REWRITE and SEO URL.
Create your website theme
on first page create form like you want
concept is like registration form and second page is edit profile
now what you stored in database from registration form
now echo in your edit profile form
for example username in database can be viewed in edit profile form
select * FROM registrationtable WHERE userid='$userid'
then store values in variables like for example
while ($query = mysql_fetch_array($request))
{
$username = $query['username'];
}
<input type="text" name="username" value="<?php echo $username; ?>"/>
p.s dont use mysql better options are mysqli and PDO
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a simple page that shows 4 different divs, all with a <h1> title (or other tag that shows text) and a form (with 1 input text) and a submit button... so far so good.
My answer is simple: I am looking for a way that:
when the user inserts a text and submit the form, the <h1> title shows the text that the user wrote
the form disappear (or takes style display:none)
this will take effect even if I refresh the page or view page in a different computer (probably need to save the data in a DB)
restart this process from the beginning (even if I need to code again).
This is for a mini game to provide to users 4 different choices and, if the user A select option 1, the <h1> will show text something like "User A was the first to choose this option. Please select a blank option" and, after the 1st raw over (point 4 described above), restart all forms.
NOTE: I am not asking in the way to "please do the code for me". I also searching for a way to store data in <php ?> - finding redbeanphp project.
I am also a newbie in SQL (just started to study SQLi last month to android development). My question is ONLY to looking for the best way to do this and what I need.
This would be the workflow:
When you click a button to submit the form JavaScript will send the form data to the server as an AJAX request and wait for a response from the server.
The PHP code on the server will read the data from the AJAX request and save it in a database and echo a success response along with the text to display.
Your JavaScript will receive this success message and hide form from the DOM and display the text in the header.
If you want the data to persist on the page on reload then you can save a flag in PHP session. Sessions persist in until you close browser window.
4.1 Use another AJAX call remove the flag from the session and reload the content.
So, if you are good with HTML and CSS you need:
JavaScript, AJAX, a JavaScript library to make things easier such as JQuery.
A server side language such as PHP.
A database to persist data. There are many choices. I am going to recommend MySQL just because there so many tutorials for it out there.