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
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 8 years ago.
Improve this question
I just have one question. I looked through one book and the Internet and unfortunately didn't find an concrete answer. So... I have a webpage where user can log in. If the user is logged in then the bar at the top of webpage is different(user sees his own photo, name etc.). I know how to use sessions&databases in this case, but I don't know how to make this two different websites. I mean.... in the home site of my whole webpage i can write sth like (in php):
if(isset($_SESSION["User"])) ..... .
But what then? I should somehow hide the html for unlogged user in "else" and part for logged user in "if" or should i create a whole new site for logged in users and redirect to this site if user is logged...? Please, help me.
It seems that you need to spend a little time looking into PHP deeper. My advice would be to learn about including PHP files in order to create a template system (so you would have a base PHP file with the HTML/PHP that is on every page (like a master page) that would include the code:
if(isset($_SESSION["User"]))
{
// Do code for logged in user...
}
else
{
// Do code for generic user...
}
Although that is a really rudimentary example, you could have a global variable if you need things on specific pages too. If you have a more specific question about implementing it, feel free to ask.
one cool thing that you can do in PHP is include html "inline". eg:
if(isset($_SESSION["User"]))
{
?>
<p>Welcome User! <?php echo $_SESSION["User"]; ?></p>
<?php
}
else
{
?>
<p>Please login to see all features...</p>
<?php
} ?>
You should first set the session variable's value(eg. $_SESSION['logged_user_id']) to some value as per your website. Then assuming that you have only one page, you will have to include many php codes at the place you wanted to display user image, Hello xyzuser etc content. You will have to use "if/else" statements to check if the session variable for some user is set or not. If the session variable is set then it will be using the if block statements where you can write code to display image of the user corresponding to e.g. that logged_user_id using your db. Otherwise it will use the else part that will display your default content.
You will have to perform "if/else" checks at each place where your content has a chance to change based on the user status i.e. use the "if" statement to check if the user is logged in or not if no user is logged in then it won't go to the "if" block statements and execute the "else" part for default display. Ok.
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 website where people can search for cheapest prices of products gathered from 25 websites. It is not an e-commerce site, it's just a site trying to increase the traffic of those 25 sites.
Therefore I want to track my users after they click the products and directed to those e-commerce sites....
I have read a lot about PHP cookies but those did not solve my problem.
Thanks
If you use Google Analytics you can also track clicks as follows:
function trackOutboundLink(link, category, action, opt_label) { // google analytics tracking
try {
_gaq.push(['_trackEvent', category , action, opt_label]);
} catch(err){}
if (link.target == '_blank')
window.open(link.href);
else {
setTimeout(function() {
document.location.href = link.href;
}, 100);
}
}
then use in the <a></a>
<a onclick="trackOutboundLink(this, 'CategoryName', 'ActionName', 'LabelName'); return false;" href="whatever.html" target="_blank">External Website Name</a>
where CategoryName, ActionName and LabelName can be anything you want and will show in Analytics
you need to add a redirection php to save where they are going and redirect them manually. use
something like:
when a link to partner site is clicked which looks like: redirect.php?url=<?php echo urlencode("www.partnersite.com/products.php?productid=34"); ?>
redirect.php:
<?php
$urltoRedirect = $_GET['url'];
//save $urltoRedirect to database / increment redirection count
header("Location: " . $urltoRedirect);
?>
you can't save that data neither to cookie nor session, since cookies are kept locally and sessions expire as soon as user close the browser / or after a limited time.
The links redirecting to the sites themselves should not be writtent directly, instead they should be something like:
The lowest price website
Redirect.php will grad the id the user wants to visite, check it, secure it, write in your DB that this id was hit, means an update on one of your tables like
UPDATE site_hits SET hits = hits + 1 WHERE id = $id;
And then directly redirect the user using a header or meta
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to create unique links (one time click) for my newsletters.
Look the steps:
I will create a link, or can be a script that will create the link http://www.example.com/page.php?unique=email#email.com
My subscriber will receive a newsletter which contains this link.
They click/visit this newsletter/link.
If they want visit it again they can't, the link will be expired, and the subscriber will be redirected to other page http://www.example.com/expired.php
So is there any chance to create this? How can this be accomplished?
I have this code
<?php
include("variables.php");
$password = trim($_SERVER['QUERY_STRING']);
if($password == ADMIN_PASSWORD) {
// Create a new key
$new = uniqid('key',TRUE);
if(!is_dir('keys')) {
mkdir('keys');
$file = fopen('keys/.htaccess','w');
fwrite($file,"Order allow,deny\nDeny from all");
fclose($file);
}
$file = fopen('keys/keys','a');
fwrite($file,"{$new}\n");
fclose($file);
?>
This script is located in a file named generate.php and if I access this url ( http://www.example.com/generate.php?1234 - 1234 is the password to generate a unique ID) will generate a unique link like this http://www.example.com/page.php?key525e1200e3a5f9.19949496 that will be only 1 time available!
Now what I want is, to access http://www.example.com/generate.php?1234&s=email#email.com
And this this generate a unique link http://www.example.com/page.php?key525e1200e3a5f9.19949496&s=email#email.com
This is for a protected download page! I need to add the user email to the download page, and this to be generated by link. 's' is the variable that will be get by the download page using $_GET['s']
Understand what I mean?
I would do this using there email.
Then do a PHP page with the following statements.
Request the GET (in this case the email address) and check if it exists in database table (lets call this - hasvisited).
IF this exists then redirect to page you want.
If doesnt exist then...
1.) Add it to DB.
2.) display 1 time page.
When step 1 happens. it will stop the user from visiting again.
If you want to restrict this to a group of specific users - as the above solution people could theoritcally type anything to get past this...
I would create table with the users already and do an IF state on a column called 'visits' and if 1 or less allow and add +1 to visits column. if above 1 visit then redirect.
I hope this make sense - should also be fairly simple to implement using PHP, MySQL DB and simple IF statement.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a very simple site (PHP) that allows user changes (via jQuery) that modify elements' classes, and add/delete rows from a table.
I want to write these changes to the actual PHP file in question on the server every time a user makes a change, so that when the page is refreshed or revisited, the changes remain intact.
What's the simplest / best way to accomplish this? Thank you!
For addition/deletion of rows, fire ajax call and update records associated with the user. This is in addition to client-side (jQuery/JavaScript) changes to page. Whenever they revisit/refresh the page, data will be fetched from db, and as such will always be latest.
When you say that users modify elements' classes, I assume you mean their page's looks and styling (like some sites have on-page options to change background color, font-sizes). If that is the case, I suggest you:
Create a list of all possible states and store them in a new table in db, say display_options. You could store details like option_type (e.g. background color, font-size etc) and option_back_value (e.g. #FFF, #000 etc).
Create a new table say user_display_options where you store things like user_id, option_type and their chosen option_id.
While loading page, do a join on these tables using user_id. Then while creating your page, conditionally add classes etc to the page.
When user edits page, fire ajax call sending required data like user_id, option_type, option_id. As mentioned for other task, these changes to db will be in addition to client-side changes.
Also read #David 's comment to your question - it clears an important concept.