Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a 2 file PHP script which allows a user to submit a form with a single text area. This script creates a new PHP page and redirects the user to it. I would like to echo text to the user who submitted the form and no one else. Can you help with a code example?
let me know if this isnt what youre looking for and ill edit it accordingly:
HTML:
<input type = "text" name = "input">
PHP:
<?php
//user input
$userInput = $_POST['input'];
//not sure how you are getting the email adress but however youre getting it it goes here
$email = "placeholder#123.com";
//create the filename
$myFile = $userInput . ".php";
//create the file
$fh= fopen($myFile, 'w');
//write to the file
fwrite($fh, $email);
//redirect to the new file
header("location:". $userInput .".php");
?>
basically it creates a new page based off of whatever your user entered and displays an email address to them. I suppose it kind of only allows the user to see it, as it is based off of what they type. other wise the best way to do this would be to store a cookie on the users system (as far as the security goes)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to make a php|html code which will do the following things
First i have an input when we submit our urls
And when we submit an url like "example.com" i will have an array which has some path names
name1.php
name2.php
And if that files exist on that domain the output is going to be true if not false.
I am really struggling with the connecting part i don't know how to connect to the paths and if that exist to be true the response.
I searched everywhere but i didn't find anything related on this.
Thanks!
I got the basic of what you need.
First, I am giving the code then I will give the helpful links.
<html>
<form method="post">
<input type="url" name="url" /><br>
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$file = $_POST['url']; //The link submitted
$file_headers = #get_headers($file); //We retrieve the headers of the link
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
//If the header above(which indicates the page doesn't exist) returns true we will show this
$exists = "The page Does not Exist";
}
else {
//If returns true we gonna show this
$exists = "The Page Exists";
}
echo $exists;
}
?>
</html>
I think this is the basic thing you need. You told you want to search for some files stored in an array. You can easily do that using this code by putting the page names after the link like this:
$file = $_POST['url'];
$finalurl = $_POST['url']."name1.php";
Know more about get_headers in PHP here
Working Demo
Hope this helps
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have Iframe that inserts data into my DB from another websites using $_SERVER['HTTP_HOST'] value.
One of the column inserted is website URL that can start with
www (e.g: www.viber.ge) or without it (just viber.ge).
I need to compare URL that Iframe has already inserted into DB to URL that Iframe is on at the moment.
But there can be www as subdomain name
So how can I be sure starting www is subdomain or not?
(I putted hello at the top but it is not showing up -_- )
Question is not about comparing "www.viber.ge" with "viber.ge"
it is more about comparing "www.www.viber.ge"(which I think can be inserted into the DB as "www.viber.ge")
with www.viber.ge (which I think can be inserted into DB as "viber.ge" or "www.viber.ge").
Additional question:
is it possible user to go to "www.www.viber.ge" and $_SERVER to save it as "www.viber.ge" (subdomain)?
You can use str_replace and remove the shorter url from the longer.
If what is left is "www." Only then it's the same domain.
$url1 = "www.viber.ge";
$url2 = "viber.ge";
If(strlen($url1) > strlen($url2)){
If(str_replace($url2,"",$url1) == "www."){
Echo "same domain";
}Else{
Echo "not same";
}
}Else{
If(str_replace($url1,"",$url2) == "www."){
Echo "same domain";
}Else{
Echo "not same";
}
}
https://3v4l.org/XtHWr
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Just as an example:
http://domain.com/main.php(then the database file here).
I'm not sure what that is even called, but I can't find anything on it.
Of course you can use GET parameters
http://domain.com/main.php?foo=bar
Which you can get in PHP with:
$_GET['foo'];
I don't really know why you want to pass the database name in the link. Sure, it can be a parameter, but it so unsecure!
UPDATE: you may use more/multiple databases, but use then a config file. The connection names or database names do not passed in the url.
.../main.php?state=demo&type=1, .../main.php?state=demo&type=2, etc.
if ($_GET['state'] == 'demo')
{
switch ($_GET['type'])
{
case 1:
$databaseName = 'demo_type_1';
break;
case 2:
$databaseName = 'demo_type_2';
break;
default:
throw new Exception('Wrong demo specified');
}
// connect to database with the name in $databaseName
}
else
{
// Other connection
}
Better is to set demo state to session, so you can read out it without the url (more secure)
It is not recommended to put your database name in GET requests in the query string for security reasons. But, if you still need it you can do:
http://domain.com/main.php?database_name=MyDatabase
Then on the PHP Code:
<?php
$databaseName = $_GET['database_name'];
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to use a MySQL database to verify that a user has bought a program from my site. I don't need to use a database, but this is the easiest way that I though this could be accomplished (any suggestions on different ways to accomplish a purchase-verification system are greatly appreciated).
My current algorithm:
User pays for the program (through one of various payment gateways provided by WooCommerce)
User is given a unique, randomized hex string by the server (this string is also stored in the database, as a key/value pair; string: 0; the 0 signifies unused)
User enters the string into the program (required), which sends an HTTP request (which includes the string) to the server. This request tells the server to look for the given string in the database. If it's found, change it's value to 1 (used). If the value is already 1 OR the string cannot be found, send an error report back to the user (program will not work).
If everything works correctly, the user can now use the program.
I have to use the HTTP request because only the server can edit the database. My website uses shared hosting, so I cannot directly modify the database on any local user.
I've never worked with databases before, but I know I have to use the INSERT, CREATE TABLE, UPDATE, and SELECT commands. In addition, I've never directly worked with HTTP requests.
How should the HTTP request look like, and how do I handle them on the server? Any other tips on how to work the database would also be appreciated.
Note: I'm probably going to use PHP (server-side) and Python (client-side).
Your html would look like this
<html>
<body>
<form action="validate.php" method="post">
Name: <input type="text" name="name"><br>
unique string: <input type="text" name="uniqueString"><br>
<input type="submit">
</form>
</body>
</html>
And on the server side, your validate.php would look like this.
<?php
$name = $_POST["name"];
$unqString = $_POST["uniqueString"];
//connect to your DB
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
$data = mysql_query("SELECT uniqueStringUsedFlag FROM <stringTableName> WHERE uniqueString='.$unqString.'")
or die(mysql_error());
while($info = mysql_fetch_array( $data )) {
if $info['uniqueStringUsedFlag']==1{
return 'Error Message';
}else
{
mysql_query("update <stringTableName> set uniqueStringUsedFlag =1 where uniqueString='.$unqString.'");
return 'Success';
}
}
//if the control comes here, it means the record was not found.
return 'Error message'
?>
Replace < stringTableName > with your actual table name.
And do the same with the columns too.
PS: This code is untested. And please do proper validations, etc. Haven't included that here.
Let me know if this works.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to get a variable which I declared in one php file to another without including the whole first php
while($row = mysql_fetch_assoc($sql)) {
// Urlaubstage ausgeben
if($row['frtutage'] < 1) {
$verbraucht = "0";
} else {
$verbraucht = $row['frtutage'];
}
$resturlaub = $row['miturlaubstage'] + $row['mitutagevorjahr'] - $verbraucht;
$urlaubgesamt = $row['miturlaubstage'] + $row['mitutagevorjahr'];
I need the variable $resturlaub in the second PHP without calculating the variable again.
How do I do this? Or is it even possible?
Thanks.
edit: the first php file is about calculating vacation days and how much I have remaind after taking a few vacation days, in the second file I need the calculation of the remaining days then, so I just want to use the variable again and not calculate it again
You can try somehting like
$var = 'random_query';
$page= 'yourpage.com/?my_var='.serialize($var);
header("Location: $page");
exit;
and in your page you can get the value by
if (isset($_GET['my_var']))
{
$my_var = unserialize($_GET['my_var']);
}
But it would depend on the size of that variable that you need to pass, and what is the purpose of the scripts.
If you don't want to include the whole first php file but only a variable then you should create a third file (called: variables.php or config.php for example).
Then include variables.php in both file so the variable will be shared among your scripts