bilis_money Posted July 1, 2006 Share Posted July 1, 2006 hi, php gurus.I hope you could help me with this puzzle?let say i have 2 files.This will display the hyperlink image and assign the value of the $myvar.file1.php[code]<?php $myvar = 2; echo "<a href=\"file2.php\" >"; echo "<img src=\"my_img.gif\" border=\"1\">"; echo "</a>";?>[/code]//and now this will display the image info and the $myvar value.file2.php[code]<?php echo $myvar; echo "<img src=\"my_img.gif\" border=\"1\">"; ..... echo more info here ....?>[/code]now how would i do this?I need your advice what should i do with this? to be able to redirectto file2.php and display the image info and carry the $myvar value thendisplay too?thank you very much in advance. Quote Link to comment https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/ Share on other sites More sharing options...
wildteen88 Posted July 1, 2006 Share Posted July 1, 2006 If its the hyperlink and the variable are stored in file1.php then use include where you need to show the image and use the variable. Quote Link to comment https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/#findComment-51667 Share on other sites More sharing options...
bilis_money Posted July 1, 2006 Author Share Posted July 1, 2006 thanks for the attention [b]wildteen[/b]i think my explaination was misleading.ok, let me clear my story again.What i want to do here is to click the image in file1.php thenat that moment the $myvar should carry the value into file2.php.so that i can use the $myvar again into file2.phpnow my question is should i use session here now to do this?thank you again very much in advance.-I hope i could help people in need with their php problems too.-maybe in the future. Quote Link to comment https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/#findComment-51668 Share on other sites More sharing options...
scraptoft Posted July 1, 2006 Share Posted July 1, 2006 Do you want to pass $myvar through the hyperlink?[code]<?php $myvar = 2; echo "<a href=\"file2.php\" >"; echo "<a href="file2.php?myvar=value"><img src=\"my_img.gif\" border=\"1\"></a>"; echo "</a>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/#findComment-51673 Share on other sites More sharing options...
Orio Posted July 1, 2006 Share Posted July 1, 2006 Two ways:[b]1[/b]) The easy way (not the best way at all)- Pass it with url variables, this way:[code=php:0]$myvar="something";echo('<a href="nextpage.php?myvar='.$myvar.'"><img src=....></a>');[/code]And in the next page you can do:[code=php:0]$myvar=$_GET['myvar'];[/code]To get the var.Why is this bad?a) People can change the value of myvar to whatever they want.b) People can see what myvar contains (in case its a password, a credit card number etc', this is NOT recomended).[b]2[/b]) The better way- Sessions.Sessions let you "save" variables.(You can read tons of tutorials about sessions, I suggest you to start with [url=http://www.tizag.com/phpT/phpsessions.php]this one[/url]).Baiscly, that's how the script will look:[hr][code=php:0]//This is page1.phpsession_start(); //Make sure this is at the VERY begining of the page//more html stuff, tags etc'$myvar="something";$_SESSION['myvar']=$myvar;echo('<a href="nextpage.php"><img src=....></a>');[/code][hr][hr][code=php:0]//this is nextpage.phpsession_start(); //Make sure this is at the VERY begining of the page$myvar=$_SESSION['myvar'];echo $myvar;[/code][hr]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/#findComment-51674 Share on other sites More sharing options...
bilis_money Posted July 1, 2006 Author Share Posted July 1, 2006 Thank you for your worthy reply [b]Orio[/b].your explaination really make sense. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/#findComment-51677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.