How do you pass a variable using GET when a text link is pressed? The only difference is that it reloads the current page but this time with a new value for the variable so it would be like it passed the new value to itself. Like if it were a gallery, it would just refresh itself with a new picture depending on the text link pressed. Pardon if my question isn't all clear, I'm kinda new to php and am still trying to learn the ropes.
You would just use this format: <a href='yourpage.php?var1=bob&some_var=32fd1'>anchor text</a> -the mole
This is how I do it... <a href="http://sitename.com/index.php?page=contact-us">Contact Us</a> <?php content = "content/" . $_GET["page"] . ".php"; include "template.php" ?> and inside template.php <html> <head> </head> <body> <?php include $content; ?> </body> </html> you should make sure only certain values are allowed so spammers don't try to dig up a file from a different part of your site.
Basically someone could pass values through $_GET[page] that would allow them to access files that could compromise your system or get info you don't want them to get (eg, /etc/passwd your db login info file, whatever pretty much). You should change the first line of clinton's post to this: $content = 'content/'.basename($_GET['page']).'.php'; basename will just return the filename from a path, so it would strip out all the other junk. This will cause problems if your file is in a subfolder in content/ since it's stripping out that subfolder. -the mole
I ran a small test but the image won't display. Check it out: <?php //The name of the file is "main.php" if(isset($_GET['pic'])) { $thispic = $_GET['pic']; } else { $thispic = 1; } $paths[1] = "orange.jpg"; $paths[2] = "green.jpg"; $paths[3] = "red.jpg"; ?> <img src="<?php $paths[thispic]?>" /> <a href="main.php?pic=1">Orange</a> <a href="main.php?pic=2">Green</a> <a href="main.php?pic=3">Red</a> Code (markup): Did I miss anything?
Hello, Replace your following code <img src="<?php $paths[thispic]?>" /> PHP: with <img src="<?php echo $paths[$thispic]; ?>" /> PHP: Hope this will solve your issue. Regards,
addition you should screen all variable, so instead of you must ensure that get['pic'] only contain what you want them tyo be ( in your case, pic must be equal to 1 or 2 or 3 ) so why not use is a longer code, and more writing, but if you get yourself used to it, you'll have arelatively more secure website.