If I have a php page that will save data from a form to the database then I want to forward that person to another place, do I have to put header( 'Location: URL ); at the end of the PHP script, or can I put it at the begining of the script and it will forward them to that page but the php script will continue to run until finished?
The script will run either way, just be sure not to print anything before calling the header() function, else it's going to be ignored.
Related
I want to check a file in Unix via Automic. If the file doesnt exist it should switch the host and check if the file is there.
The problem is, that I dont now how to implement a error handling.
Everytime the script object is processing and cant find the file the skript aborted. I need a new starting point in the skript but "ON_ERROR" or ":RESTART" doesnt work.
How can I implement a logic like this: IF the script aborted due to the error-massage 'No such file or directory'start the script from here instead.
Thank you very much for your help!
Best regards
I have solved it. Use the function PREP_PROCESS_FILENAME to check if the file exists in the folder!
You have to start the task twice in the same workflow. The task-job checks if the script exists otherwise nothing to do.
if [ -f "/path/to/script" ]
then
bash /path/to/script
else
echo "Script not found"
fi
In Post-Script you can modify the state for the empty task with :MODIFY_STATE. Depend on report or returncode
I have a simple Jmeter test where I have a property to set the URL. The PATH in the Jmeter test is set to the following.
${__P(GET_URL,)}
This works well for all URLs that I have been working with, except for the ones where I need to pass a variable in the URL component.
For example, it works for http://server:port/getemployeelist when I run the test with -JGET_URL=/getemployeelist
Then I created a CSV config element to populate the variable EMP_ID.
Then if I run the test with -JGET_URL=/getemployee/${EMP_ID}, the EMP_ID variable is not getting substituted. Jmeter test gives me an error as follows:
java.net.URISyntaxException: Illegal character in path at index xx: https://://getemployee/${EMP_ID}
Appreciate any help/pointers.
It will not work this way, JMeter doesn't know anything about ${EMP_ID} at the time it is being started, you need to append this ${EMP_ID} to HTTP Request sampler "Path" in the runtime
Start JMeter as:
jmeter -JGET_URL=/getemployee/
Use CSV Data Set Config to read the EMP_ID from the CSV File
In the HTTP Request sampler use construction like /${__P(GET_URL,)}/${EMP_ID} to combine JMeter Property specified via -J command line argument and JMeter Variable originating from the CSV file.
If anything goes wrong first of all check jmeter.log file - it normally contains enough troubleshooting information. If there is nothing suspicious - use Debug Sampler and View Results Tree listener combination to inspect requests and response details, variables and properties names and values, etc.
Had asked this question a while back. Thought of posting the solution which I eventually ended up implementing. In the solution, I created a template jmx with a substitution variable for the HttpSampler.path and then replace the path at runtime. Following are the key points from the scripting done.
This turned out to be a simpler solution that worked for all kinds of API call patterns.
Created a template jmx (jmeter_test_template) with the following line.
<stringProp name="HTTPSampler.path">#PATH#</stringProp>
This jmx has CSV config element to populate variable "EMP_ID". To create this file, just create a new test with any URL and then save it as a template and replace the URL with substitution variable #PATH#.
Created a wrapper script like run_any_api.sh with usage,
sh run_any_api.sh URL=http://server:port/myapp/employees/${EMP_ID}
In the wrapper script, this URL is replaced in place of the token.
sed "s/#PATH#/$URL" jmeter_test_template.jmx > jmeter_test_template.current_test.jmx
jmeter -t jmeter_test_template.current_test.jmx
Last but not the least, please remember to cleanup the temporary jmx,
rm jmeter_test_template.current_test.jmx
What this actually means?
I dont understand the error. Please help me
Warning: Cannot modify header information - headers already sent by (output started at /home/mksdemo/public_html/Admin/login.php:31) in /home/mksdemo/public_html/Admin/login.php on line 84
on line no 31 only
This means you have added some echo statement before making the redirect . You should change the location and do the exit from the script and it should be done in the beginning itself
You are trying to do your redirect using the header() function, however, according to HTTP protocol, all headers have to be issued before any content is sent (using something like echo, print(), or even a closing ?> tag). It sounds like you are calling header() in
login.php on line 84
and you have something sending content in
login.php on line 31
You should make sure the header is being sent before this and all other possible lines of output.
I have multiple scripts running. All the scripts have the same name but the commands they execute are doing different things.
I am trying to figure out if a certain instance of the script is running and if so I don't want it to run again. This is difficult because all of the scripts have the same name so it could be a false positive by using pgrep.
My idea was if there is any attribute or description I could attach when it is first run, then I can grep for that unique description and tell which instance is running, is there any way to do this?
Does anyone have any other ideas?
Thanks
You can implement below logic to check weather script is already running or not.
if [ -f Script1.lck ];then
echo "ALREADY INSTANCE RUNNING `date`"
echo "EXITING"
else
echo "NO INSTANCE RUNNING "
touch Script1.lck
#Your Script code here.............
rm -f Script1.lck
fi
*I used concept that every time it runs checks for Script1.lck file if file not exists than it means no instance is running. So it creates file and start executing your code.
Suppose in between you executed the script then it checks for .lck file and and .lck already exists due to previous instance.
*In last i removed the .lck file.
*By using different lck file names for different script you can check which script is running.
I know this may be a silly question but i cant seem to find just a simple answer.
I have a php script that makes a directory for me when the user starts a new entry.
That directory holds photos for their gallery.
What i would like to do is also create One index.html file inside that new directory with a few lines of html code in it.
How do i do this?
Im guessing that the file would be made like so:
mkdir('users/'.$id.'/index.html',0755);
But how do i add the html into that index.html file?
Or do i have one file on the server and copy it over into there during the MKDIR process?
Anyways a really simple answer would be best as i am very slow in this learning thing.
Thank you
John
New edits.....
<?php
$id = 812;
mkdir('users/'.$id,0755);
chmod('users/'.$id,0777);
$fh = fopen( "users/".$id, "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
?>
Its giving me this error?
Warning: fopen(users/812) [function.fopen]: failed to open stream: Permission denied in stackoverflowtest1.php on line 9
Couldn't open file
Any ideas? I am on a wamp windows 7 server and not using ftp to edit files but just the www wamp explorer foler.
I'm not sure which language you are using so you'll either need to update your question or forgive the lack of concrete code. mkdir is for generating directories and not flat files. To do that you'll need to open then the file handle then print the HTML lines to that handle and then close it.
A file handle is a pointer to a file. It allows you to manipulate the data in that file ( i.e. read or write it ).
example code:
$fh = fopen( "path/to/file/index.html", "w+" ) or die( "Couldn't open file" );
fwrite( $fh, "<html><head /><body><h1>It Works!</h1></html>" );
fclose( $fh );
The path to the file needs a file name as a target, sorry that wasn't clear.