I need for my current project a link that provides 2x timestamp(MySQL) 1x integer and 2x char. I know how to send an email with PHP but I don't know how to put all types together in one link. After someone clicked it, it should direct you to another PHP site in which I want to call a procedure. I should be save to, therefore maybe hashing?
An example:
http://examplesite.com/teachers/accepted.php?begintime=...,endtime=...,id=...,rndchar=...,rndcharv2=...
I hope someone could help me :)
<?php
$link = "Link Text";
mail($to, "subject", $link,$headers);
?>
Then on accepted.php you will get the query strings using $_GET then if they are all set and not empty, u do what u need to do
Related
I've just designed my first form in HTML and a PHP page to display the results. In the form the user inputs some codes in response to some questions, a bit like a multiple choice, so for example, these are "ABC". The PHP page displays the code to the user as a link, which when clicked will go to a bookmark (a link within the same page) with the ID #ABC. This was achieved with simple manipulation of the PHP variable as follows:
<?php
$code = "ABC"
$part1 = '<a href="mywebpage.php#';
$part2 = '">Go to this code</a>';
$string = $part1.$code.$part2;
echo $string;
?>
(i.e. Link in the page says "go to this code" and when clicked will go to section with bookmark ABC)
This all works fine, but I simply need to know if there is a way of error trapping so that if a bookmark does not exist for the code entered, a message can be displayed to the user instead? Can this be done using the PHP variable, or do I need to use JavaScript? One work around may be to search the web page for the ID "#ABC'. Is it possible to do this? Another option would be to store an array of valid codes on the server then query this before setting the bookmark, but I want to keep it as simple as possible. Any help appreciated, thanks.
What you call a "bookmark" we call a hash. And when you say "go to a bookmark" you mean a hash change. Hash changes do not make an additional request to the server, it is all handled on the client-side, therefore this must be done with JavaScript and not PHP.
So let's just do some simple JavaScript on hash change window.onhashchange that will search for an element with that ID and if it's not found alert something.
window.onhashchange = function(){
if(!document.getElementById(location.hash){
alert("not found");
}
}
I have a question and try searching on Google and Stakoverflow and could't find any perfect solution. I am using phpmailer and want to let the user to customize it's body message. So I have given and option to edit the email body text by providing a texarea input box in back end where user will input the email text with some my own provided php variable.
For example body text is "Dear {$username}, thank you for signup.". Once I store this input into database and want to retrieve this in php:
$username = "ABC"; //username variable
$message = $row["message"]; //stored email body message
echo $message;
OUTPUT DATA: "Dear {$username}, thank you for signup."
I want to get it like this "Dear ABC, thank you for signup.". How is it possible or is there any other option I can use it with php varialbe or defined type?
You're not getting an answer you're expecting because contents of $row["message"] don't get evaluated again. And that's actually a good thing because users could use any variable name they want, which would create a security threat.
There is a quality solution, though. You should check out template engines for PHP, e.g. Smarty and Twig. They allow you to create templates with placeholders, for example something like:
Dear {{username}}, thank you for sign-up!
which you could store in a file or let your users define their own templates. Template engine will then read the template and, using the values you send it, replace those placeholders with actual values.
To see how this is done in practice, choose a template engine and check its documentation.
I have found a solution in PHP with str_replace function. This function is really very helpful. I have tried with modified input message "Dear user_name, thank you for signup.":
$username = "ABC"; //username variable
$message = $row["message"]; //stored email body message
$message_new = str_replace("user_name", $username, $message);
echo $message_new;
OUTPUT DATA: "Dear ABC, thank you for signup."
You can use PHP eval() function.
$msg = "$cust_dt->cus_name, Your order placed successfully. ID: $sms_oid Total: $sms_ord_tot";
echo $msg;//output1
eval("\$msg= \"$msg\";");
echo $msg;//output2
Output 1: $cust_dt->cus_name, Your order placed successfully. ID:
$sms_oid Total: $sms_ord_tot
Output 2: John Doe, Your order placed successfully. ID: 454554545
Total: 1600
You can store a strings like $msg in a database and use eval() function to evaluate string into php code.
For More:
https://www.w3schools.com/php/func_misc_eval.asp
https://www.php.net/manual/en/function.eval.php
Just wanted to say THANK YOU!!!!
This also works by putting ((name)), and using that inside str_replace - instead of just using "user_name"
Which is a little more user-friendly - and keeps from accidentally replacing things if someone were to type "user_name", for instance lol
Plus it'll make it look cool when having your "insert" legend at the top saying:
Choose one of the following:
((name)) = Clients Name
You saved me so much time!
Let's say I have sugarcrm cases where I know what the case id and or number is.
I want to use email to sms to send to the techs what their work is. So, the link that needs to be sent must have the id and number in it. I want to send them to a simple PHP page that just has a dropdown menu with the two options accept and complete.
so if they receive the sms, they click on the link, it takes them to the page where they click on dropdown to accept the case.
Updating from the PHP is easy: it's just an update my sql query. I need to know how to send header or info in the link that the tech receives.
something like http://tech.com/caseupdate.php?case_number?case_id
so I can use that case number/id when updating
You need something like this:
Each variable in the query string should be separated by an & as +War10ck said
i.e:
http://tech.com/caseupdate.php?case_number=[num]&case_id=[id]
Then in your PHP you can get those variables using $_GET[].
<?php
if(isset($_GET['case_number']) && isset($_GET['case_id'])) {
$casen = (int) $_GET['case_number']; // assuming you need an Int value
$caseid = (int) $_GET['case_id'];
/* do your MySQL thing here now with $casen and $caseid */
}
?>
Dont know if this is right but got it working by doing the following
<input type="hidden" name="casen" value=<?php echo $casen;?>>
Thank you all for your help.
This si an excellent site for newbis to learn and get help in a direction to solve issues.
I'm a bit new to this so sorry if this has been covered already but i'm going around in circles searching.
I've had a look around learn t how to edit htaccess and use the get function, I then even found a plugin called redirection that did similar.
What I would like to do is if I have a URL http://example.com/file.php?id=blue
is to grab the id which is "blue"
then in a href link dynamically add it to the end of another url
Link Example
If someone could help show me or point me in the right direction on how to get the id blue and add it into a href that would be great.
Many Thanks
You have to use $_GET. People might be dicks about it here - but I had a hard time when I was first learning to program too. You'll get it, don't worry.
This is how get works (at least, all you need to know about how it works):
if you have the file index.php
if you add a query string to the end of it like index.php?id=1
You can access id=1 by doing the following in your code:
$id = $_GET['id'];
Similarly if the query string contains the following index.php?id=1&page=5&par=3&club=putter&upnext=tigerwoods
On the left hand of the equal sign is the Key(id, page, par, club, upnext) and on the right side their value(1,5,3,putter,tigerwoods)
One thing to remember is that when retrieving numbers from the query string they will always be of the string type, so you cant do something like
if ( $_GET['page'] === 5 )
you'll have to do
if ( $_GET['page'] == 5 )
and to echo it into a link:
$club = $_GET['club'];
if ( $club == 'NRA' ) {
echo "Gun Show";
echo 'Buy tickets to my gunshow ^^';
}
Hope this helps!
You can also do things like set your website up so that it has one template and use the $_GET parameter to determine which files to include into the content sections of the site via a switch command. I do this, but not across my whole site. For my user control panel, I do this to simply include only the file necessary (change email, update password, delete account, update profile, etc)
Cah'piche?
Use the $_GET parameter.
YAY!!
Sorry if the title's unclear, couldn't think of anything better since I'm still new to this area. :)
Anyway, my question is this: I want to send some information from one page (let's call it 1.php) to another page (let's call it 2.php) using this (don't know the formal name, sorry):
http://localhost/X/2.php?user_id=5&user_type=2&ssn=1234567890&first_name=John&last_name=Doe
As you can see, the information is in plain text, which I dislike. Is there an easy way to encrypt the string after the question mark above in 1.php, and then let the 2.php (that gets the passed-along info) decrypt it? I'd like for it to be something along:
http://localhost/X/2.php?user_id=rj3i15k&user_type=8109fk1JIf&ssn=6893kfj399JFk...
Sorry if this is a stupid question. Many thanks in advance!
If you don't want information to be modified, use a hash string to verify them.
For instance :
$hash = sha1($user_id."haha".$user_type.$ssn.$first_name.$last_name);
The "haha" here, is a salt. Use a random string, it will be use so someone can't reuse your algorithm to inject fake data.
Then put this hash at the end of your url, eg
http://localhost/X/2.php?user_id=5&user_type=2&ssn=1234567890&first_name=John&last_name=Doe&hash=$hash`
When you'll get this information, make the hash again, and compare it to the hash sent : If the information was modified, the hash won't match.
Maybe you're going about it the wrong way.
Thought about storing the data in a serverside session variable?
Or even in a database (if you're passing to another machine), then you just need to send the unique identifier of the database entry.
page2 will then read the session variable, or retrieve it out of the database again.
Basically, keep the data serverside and then you wont need to encrypt/decrypt.
Session Example:
page1
<?
session_start();
$_SESSION['pagedata'] = array(
'user_id'=>5,
'user_type'=>2,
'ssn'=>1234567890,
'first_name'=>'John',
'last_name'=>'Doe'
);
header('Location: page2.php');
?>
page2
<?
session_start();
$user_id = $_SESSION['pagedata']['user_id'];
$user_type = $_SESSION['pagedata']['user_type'];
$user_ssn = $_SESSION['pagedata']['user_ssn'];
$user_first_name = $_SESSION['pagedata']['first_name'];
$user_last_name = $_SESSION['pagedata']['last_name'];
// use variables to do stuff
?>
Its called GET, never relate 100% on 2 Way Decryption but this may help you Best way to use PHP to encrypt and decrypt passwords?
you could use base64_encode on the one side and bas64_decode on the other - just as one possibility - but note that this is only for "better looking" url als you want it (for me, this is ugly). this isn't encrypting your data for being more safe or something like that - to achive this, use https and don't confuse your users by doing such crazy stuff.
You should use $_SESSION.