EddieRock Posted July 1, 2008 Share Posted July 1, 2008 Ok... I'm a total newbie and really want to learn PHP. I'm working on my first php page and want to have a link like this on the page that when clicked, passes the info into a new url and then opens up a new browser window and sends the user there. Link: jump.php?var=abcd Then the new browser window opens up and looks like this: http://<ExternalSite.com>/data/data1/data2/abcd/data3 where the /data/data1/data2 and /data3 stay the same but the abcd is put in the url. At this point, I don't want to use a database and don't think I need to because only one of the dir's in the external url changes. Sorry, I know this is a newbie question, but remember... at one time, you all were where I am now thanks again, EddieRock ~newbie Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 1, 2008 Share Posted July 1, 2008 So what's the question and what's the point of passing all that crap in the URL? Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Like this? header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['var']."/data3"); Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 1, 2008 Author Share Posted July 1, 2008 Like this? header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['var']."/data3"); Yes, but I guess I missed the question... I'm looking for the code (all of it) for the file jump.php that would pass the variable. can you help with this? Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Put this all in the same file: <?php if (isset($_GET['var'])) header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['var']."/data3"); else echo "<a href=\"?var=abcd\" target=\"_blank\">link</a>"; ?> Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 1, 2008 Author Share Posted July 1, 2008 Really... That's it? Cool, Thanks a bunch. You guys are great. I spent a better part of 3 days searching for this answer. I'll try it tonight. Is there any security issues with this? Also, I want to really start learning php. What is the best path to take? Books? Class? Recommended websites (other than this great one!!)? EddieRock ~newbie Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 1, 2008 Author Share Posted July 1, 2008 Put this all in the same file: <?php if (isset($_GET['var'])) header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['var']."/data3"); else echo "<a href=\"?var=abcd\" target=\"_blank\">link</a>"; ?> This does work but I have two questions... In the code in the echo statement, it has this: "?var=abcd\" which is what I did in my "post example" (above) for my site but the abcd will always be different for each link I make. Does this matter? what does this do? Also, it does not open up in a new window for the target. This is in the code above (in the echo statement) and it doesn't seem to do anything... Thanks all for helping on this!! EddieRock ~newbie Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 You can switch "abcd" out with whatever you want. You probably want to use a variable to do so like this: $link="abcd"; echo "<a href=\"?var=$link\" target=\"_blank\">link</a>"; It should open in a new window. What browser are you using? I know it works in IE 6 and I think browsers with tabs will open it in a new tab. Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 2, 2008 Author Share Posted July 2, 2008 You can switch "abcd" out with whatever you want. You probably want to use a variable to do so like this: $link="abcd"; echo "<a href=\"?var=$link\" target=\"_blank\">link</a>"; It should open in a new window. What browser are you using? I know it works in IE 6 and I think browsers with tabs will open it in a new tab. the abcd was the inital variable so I don't think it should be in the code. I'll explain it again... I have a site that will link to a URL with everything the same except a product code. So... I want a .php file to imput everything in the URL except the product code. My link on the page will look like: <a href="jump.php?var=asdf">Product Link</a> Please note that the asdf in the link will always be different So shouldn't the $link="abcd"; be like this or something... $link="var" Not sure as I'm a very green newbie. thanks, EddieRock ~newbie Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted July 2, 2008 Share Posted July 2, 2008 can you give us a list of expected input and output so we can see wht you want to be doing? thanks Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 2, 2008 Share Posted July 2, 2008 <?php $id = "abcd";// assign product code id to a variable ?> <a href="jump.php?prod=$id">Product ID link</a> The code above goes in your first page then inside jump.php put this <?php if (isset($_GET['id])) header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['id']."/data3"); else header("Location: http://BackToFirstPage"); ?> I think this is what you are after Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 2, 2008 Author Share Posted July 2, 2008 PC Nerd: That is at the beginning of the thread... I've added it so you don't have to scroll up... In the quote below, the abcd in the destination url is what changes for each product (the variable) and I need the .php file on my website to open up a new window and put the variable in the destination url. Pretty simple. I'm just looking for the code. We have it working here but asked a simple question. In the echo line, the "?var=abcd\" has the abcd in it which is the variable: <?php if (isset($_GET['var'])) header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['var']."/data3"); else echo "<a href=\"?var=abcd\" target=\"_blank\">link</a>"; ?> Ok... I'm a total newbie and really want to learn PHP. I'm working on my first php page and want to have a link like this on the page that when clicked, passes the info into a new url and then opens up a new browser window and sends the user there. Link: jump.php?var=abcd Then the new browser window opens up and looks like this: http://<ExternalSite.com>/data/data1/data2/abcd/data3 where the /data/data1/data2 and /data3 stay the same but the abcd is put in the url. At this point, I don't want to use a database and don't think I need to because only one of the dir's in the external url changes. Sorry, I know this is a newbie question, but remember... at one time, you all were where I am now thanks again, EddieRock ~newbie Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 Please note that the asdf in the link will always be different When you say it will always be different, where exactly are you expecting it to come from? Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 2, 2008 Share Posted July 2, 2008 i was thinking the same thorpe. as for this "?var=abcd\" var is the name of the variable you will be retrieving using $_GET and abcd is the value that is going to be stored in that variable. How i did it was assign the contents of one variable into another as you said the code will be changing all the time i presume you will be setting a variable somewhere else in the script with a product id Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 2, 2008 Author Share Posted July 2, 2008 Ok... I caved... Here is a test page. http://www.therockwells.net/test.php the B0001YEOCU is a ASIN for Amazon that is a product. I want to construct links but only want to change the Amazon ASIN product code. It does work except for the open in a new window. Also, my question is that I think this should not be static (In RED): echo "<a href=\"?var=abcd\" target=\"_blank\">link[/url]"; What code changes do I need to make to the code below? <?php if (isset($_GET['var'])) header("Location: http://amazon.com/exec/obidos/ASIN/".$_GET['var']."/productlinks-20"); else echo "<a href=\"?var=abcd\" target=\"_blank\">link</a>"; ?> Thanks all for your help!! EddieRock ~newbie Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 What code changes do I need to make to the code below? To make the code below do what? By the way, php doesn't even know what a browser is let allone how to open a new window. That is all client side (javascript / hml) controlled. Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 2, 2008 Author Share Posted July 2, 2008 What code changes do I need to make to the code below? To make the code below do what? By the way, php doesn't even know what a browser is let allone how to open a new window. That is all client side (javascript / hml) controlled. The code does work. I realized that I need to open the new window outside the php script. It's just an easy way for me to not have to get the product links for each and every product I want to link to. All I need to do is to use the jump.php with the ?var=BIRKCI940D. Now the ONLY question is this line in regards to the echo line. The "?var=abcd\" in the code (someone who understood what I was looking to do) wrote for me has the abcd in it which is what I put in my inital example. As I said it does work but I want the code to be correct. I don't think the abcd is correct. If you can look at my first two posts in this thread, you will get it. Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 Maybe you simply want.... <a href="http://amazon.com/exec/obidos/ASIN/<?php echo $_GET['var']; ?>/productlinks-20" target="_blank">link</a> Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 2, 2008 Author Share Posted July 2, 2008 Maybe you simply want.... <a href="http://amazon.com/exec/obidos/ASIN/<?php echo $_GET['var']; ?>/productlinks-20" target="_blank">link</a> This code just opens a new page (in browser session) with the word link which is a URL of the above. If clicked, I go there but I want it to auto send to url in a new window on initial click. Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 On initial click of what? The link? Sorry, but Id'e suggest you learn how php passes variables around via $_GET, from there you can simply do this yourself. The way it is now you don't know enough to even explain clearly your intent, this is just going around in circles. Besides, were not here to simply write the code you ask for, this is a help forum, not a do forum. Quote Link to comment Share on other sites More sharing options...
EddieRock Posted July 2, 2008 Author Share Posted July 2, 2008 Here is what I put together (from each post in this thread) and seems to work... The code in jump.php is: <?php header("Location: http://amazon.com/exec/obidos/ASIN/".$_GET['ASIN']."/productlinks-20"); ?> I then have a link with this url: jump.php?ASIN=B000144I2G and IT WORKS!!! Thanks all for your help!!! If you see anyting I should change, let me know! EddieRock Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 2, 2008 Share Posted July 2, 2008 this <a href="jump.php?var=B000BY52NU">Another Nikon Lens</a> needs to be <a href="jump.php?var=B000BY52NU" target="_blank">Another Nikon Lens</a> Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 You say the link will always be different but you don't say where you get these different links. This code will make the link from whatever you put into the text box. Is that what you are trying to do? <?php if (isset($_GET['var'])) header("Location: http://<ExternalSite.com>/data/data1/data2/".$_GET['var']."/data3"); else echo "<form><input type=TEXT name=\"var\"><input type=SUBMIT></form>"; ?> Quote Link to comment 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.