I am looking to change an URL on my site when sending a PM to use a user I click on the PM icon and get the URL as:
index.php?page=usercp&do=pm&action=edit&uid=10&what=new&to=ObieWan
I need that URL to be able to work for any user to send ObieWan a PM but it won't work as it's using my uid of 10.
The link looks like as follows and is in a .php file:
<font size="1">PM ObieWan</font>
Get the id of the current user and give it to the url like:
<?php
echo"
<a href='index.php?
page=usercp&do=pm&action=edit&uid='".$id."'&what=new&to=ObieWan'>This is the link
</a>";
?>
I have no idea about the rest of your code or database structure so you should get the ID from the user you want yourself. This is the way to pass the ID of the current user
If its the uid that you want to change then you can use $_GET['uid'] to set it.
Related
how can I pass a parameter in a URL to a link on the page. So we have this link setup for all visitors from Facebook.
http://www.domain.com/event?source=facebook
We need to pass the source to the end of a link on the page which leads to a booking engine and registers as a conversion so that
http://www.bookingengine.com/tickets/1234/?ticket=567&event=8910
becomes
http://www.bookingengine.com/tickets/1234/?ticket=567&event=8910&source=facebook
Use <?php echo get_permalink($post_ID)."&source=".$yoursource;?> as your link, or something to that effect.
I am new to PHP and javascript programming
I have a string that can be "abc" or "aac" or "aaa" etc based on the inputs given by the user. After the user clicks some button(say submit) I want to generate a dynamic link like www.domain.com/abc or www.domain.com/aac based on string and navigate the user to the generated link. Is this possible?
Thank You
You can actually define a function and set it your form action. Then taking the user input it will be really each in the function to use header('location:YOUR_SITE_URL/'.$_GET['user_input']); die; for redirecting the user to desired url.
Hope that helps.
Yes it is possible, you can pass the string variable throw POST or GET when the user click submit
and then echo the link you want with the string congrenated. assuming you want to use php take a look at the example
$adress = "www.domain.com/";
$string = $_POST["get_string"];
$result = $adress + $string;
echo $result;
Possible, using routing. A real world example is how your usernames get to be part of the URL in social sites like Facebook.
What you need is a database of some sort to store the string, and it's matched data (could be an ID, or some identified) to tell the server what to load when that string is received. You'd also need routing code, which parses the entire url in search of that certain segment which should contain the string. This is how routing works in frameworks like CodeIgniter, Connect and Express.
In JS, routers in Connect look like:
app.route('/users/:username',function(username){
//okay! we got the username!
//now we'll look for it in the database if it's there
});
For PHP, here's an article regarding URL parsing.
In PHP :
Use methode in your page and store the variable to $UrlName (for example)
and continued with
echo("<script>location.href = \"www.domain.com/" . $UrlName . "\";</script>");
First in page1.html:
<form method="post" action="page2.php" >
String: <input type="text" name="string" />
<input type="submit" />
</form>
Then in page2.php:
header('location:www.domain.com/string/'.$_POST['string']);
But you should put a .htaccess containing:
Redirect /string/(.+) /page3.php?string=$1 [B,QSA]
And page4.php:
echo $_GET['string'];
This is the code. editor.php is the link. photo_id is the the information i want to pass over. $photo['picture'] is the photo.
print ('<img src='{$photo['picture']}'.''./>');
Just use session_start(); and put you link in a $_SESSION['last_link']; and use the same function on the next page and access the value you have put in $_SESSION['last_link'] to get information about the photo and display it.
PHP Sessions
Or, if you used that kind of link, in the editor.php you can use $_GET['photo_id'] to get the id of your photo, after the user have clicked on the image to follow the link.
Edit 1:
You could try putting the right concatenation:
try this:
echo '<img src='.$photo['picture'].' />';
Is there a way to put a php variable in an without it automatically being visible, like a GET variable?
Some click
I want the subsequent browser URL to be www.myphpfile.php (no variable visible).
Thanks for any help.
If I understood you right you want to have something like this:
Start a session and write the contents of $_GET['location'] into, e.g., $_SESSION['location'].
Redirect the user, e.g. header('Location: myfile.php');
If the user changes his location, start at 1
You could create a form for it with method="post" and style the submit button as a normal link using CSS.
That is if I understood you question correctly.
You should use <a href="fake" onclick="window.location=real">, but I prefer use links as The Lord W3C has declared originally.
Edit:
<a href="javascript:goto(nice_url_like_thing)">;
.a little help guys..
I have an index.php page which contains tags which when clicked opens up picture.php.
.my picture.php is a page that retrieves images from a certain database depending on what is the idno.
.what i want to do is to add an "idno" attribute on my anchor tag that when the user clicks a certain tag the index.php sends the idno to my picture.php so that the picture.php knows what image to fetch from the database. help pls!
So for your anchor tag, could you do something like this?
<?php
$url = "pictures.php?idno=" . idno;
echo "Click Me";
?>
Now in your pictures.php file, you can read the ID like this:
$idno = $_GET['idno'];
The only thing to watch out for is to make sure you sanitize that input, before you pass it off to a database query so you aren't vulnerable to a SQL injection attack.
You can send the parameter to picture.php via GET
Blah!
You could use GET to pass idno to pictures.php
so your link would look like this:
<a href='/picture.php?idno=12345678'>My Picture Tag</a>
In your picture.php:
$idno = $_GET['idno'];
Make sure you sterilize $idno before using it in a MySQL query. If idno is a number, then you can also check if it's an integer:
$isInt = is_int($idno);
Picture # <?php echo $idno ?>
Figuring out how to set $idno is left as an exercise to the OP.