Jump to content

PHP url variable passed to new window external site


EddieRock

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Really... That's it?  :o

 

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

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.