PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a simple script (written in php) that uses GET to transfer
variables, and I want to use sessions instead of GET.
How do I do it ? (Any code would be greatly appreciated,
because I learn this better if I have a fully functional script I can study !!!)
If I am understanding your question correctly, you want to grab information for the URL and then display something based on that. To do this, GET and REQUEST (pretty much same thing) are the only ways to do this. I guess you could always use javascript to parse the URL and then set a session variable. Or the same w/ php. Both of these seem tedious and not worth the effort though. Maybe you could explain in more detail what you are trying to do.
I'm trying to hide the information (in other words: not to display variables in URL) from user and to have the same functionality as in the script I posted. I don't want to use javascript, because some users have disabled it from browser's settings.
Here is how I would do it. Make a form that uses POST and a drop-down menu w/ onclick form submission. Try this and let me know if this works for your purpose:
Assume the page w/ this on it is called test.php. In other words, the form action must should be the same as page it is on.
1. Instead of links, use buttons. That would allow you to submit the form when one is clicked, use the post method as in the previous code, and display the value. There may be some way you can destyle a button as well so it looks like a link, but I don't know about this off the top of my head.
2. Use links. Without using the get method I can only think of one solution. Grab the url for the page, parse it using substrings or regular expressions, and then display the correct information based on the parsed url.
3. You mentioned about not displaying the variable in the url. You could always use something like ?id=2 and in your code, if id=2 echo the hat information for example, or if id=3 echo the jeans information.
If I think of anything else I'll be sure to post. Also, if you want more information on any of these let me know.
timodemus wrote:How do I make a button that uses any picture of my choise (and not using javascript)?
Tutorial on html buttons
Here is the example they give on the website:
<input type="image" src="rainbow.gif" name="image" width="60" height="60">
You use src to point to the image you want to use as the button.
How do I make a form that has
<input type="image" src="rainbow.gif" name="image" width="60" height="60">
and sends product=hat by POST, by pressing this button?
PS: I haven't made any forms myself, yet.
PPS: I speak finnish better than english.
timodemus wrote:How do I make a form that has
<input type="image" src="rainbow.gif" name="image" width="60" height="60">
and sends product=hat by POST, by pressing this button?
I now realize that isn't a very good solution either (since buttons can not receive values directly), but if you want to use it, you could do the following:
Thanks again, I can now do the thing I wanted to.
The script I posted was just a bad example, I'm not making an online shop.
I want to use links, because I make dynamic pages such as http://www.tammelantyosali.net/
(Click on the picture and then click "Työtoiminta" on the left and follow the links on the center.)
Another question: is it possible to make a php script that makes an image from any text automatically?
timodemus wrote:Another question: is it possible to make a php script that makes an image from any text automatically?
If you have the GD library installed, it's pretty simple:
to build an image from scratch, use imagecreate()
to build an image from a predrawn image, use imagecreatefromjpeg()
Then you will add more information onto the image with various functions
usually, you will create a script "buildimage.php" and link to it like so: