Jump to content

Recommended Posts

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 redirect
to file2.php and display the image info and carry the $myvar value then
display too?

thank you very much in advance.
Link to comment
https://forums.phpfreaks.com/topic/13380-carrying-myvar-with-the-image-hyperlink/
Share on other sites

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 then
at that moment the $myvar should carry the value into file2.php.

so that i can use the $myvar again into file2.php

now 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.

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.php
session_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.php
session_start(); //Make sure this is at the VERY begining of the page
$myvar=$_SESSION['myvar'];
echo $myvar;[/code]
[hr]


Orio.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.