<div class="userDet">
<?php
echo "Welcome to the server, $steamid! </br>"
echo "Map: $map</br>"
echo "Enjoy your stay."
?>
</div>
while this works loading it up locally, when i connect to it on my webiste i get the following error:
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ':' in /home/u272437591/public_html/yes.html on line 29
Website:http://justin-wood.tk/yes.html
if you want the full html code just ask
You forgot to put semicolons
<div class="userDet">
<?php
echo "Welcome to the server, $steamid! </br>";
echo "Map: $map</br>";
echo "Enjoy your stay.";
?>
</div>
Related
I want to launch a bash script when a button is pressed on a website.
This is my first attempt:
<button type="button" onclick="/path/to/name.sh">Click Me!</button>
But no luck. Any suggestions?
As stated by Luke you need to use a server side language, like php.
This is a really simple php example:
<?php
if ($_GET['run']) {
# This code will run if ?run=true is set.
exec("/path/to/name.sh");
}
?>
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
Click Me!
Save this as myfilename.php and place it on a machine with a web server with php installed. The same thing can be accomplished with asp, java, ruby, python, ...
This is really just an expansion of BBB's answer which lead to to get my experiment working.
This script will simply create a file /tmp/testfile when you click on the button that says "Open Script".
This requires 3 files.
The actual HTML Website with a button.
A php script which executes the script
A Script
The File Tree:
root#test:/var/www/html# tree testscript/
testscript/
├── index.html
├── testexec.php
└── test.sh
1. The main WebPage:
root#test:/var/www/html# cat testscript/index.html
<form action="/testscript/testexec.php">
<input type="submit" value="Open Script">
</form>
2. The PHP Page that runs the script and redirects back to the main page:
root#test:/var/www/html# cat testscript/testexec.php
<?php
shell_exec("/var/www/html/testscript/test.sh");
header('Location: http://192.168.1.222/testscript/index.html?success=true');
?>
3. The Script :
root#test:/var/www/html# cat testscript/test.sh
#!/bin/bash
touch /tmp/testfile
PHP is likely the easiest.
Just make a file script.php that contains <?php shell_exec("yourscript.sh"); ?> and send anybody who clicks the button to that destination. You can return the user to the original page with header:
<?php
shell_exec("yourscript.sh");
header('Location: http://www.website.com/page?success=true');
?>
Reference: http://php.net/manual/en/function.shell-exec.php
This is how it look like in pure bash
cat /usr/lib/cgi-bin/index.cgi
#!/bin/bash
echo Content-type: text/html
echo ""
## make POST and GET stings
## as bash variables available
if [ ! -z $CONTENT_LENGTH ] && [ "$CONTENT_LENGTH" -gt 0 ] && [ $CONTENT_TYPE != "multipart/form-data" ]; then
read -n $CONTENT_LENGTH POST_STRING <&0
eval `echo "${POST_STRING//;}"|tr '&' ';'`
fi
eval `echo "${QUERY_STRING//;}"|tr '&' ';'`
echo "<!DOCTYPE html>"
echo "<html>"
echo "<head>"
echo "</head>"
if [[ "$vote" = "a" ]];then
echo "you pressed A"
sudo /usr/local/bin/run_a.sh
elif [[ "$vote" = "b" ]];then
echo "you pressed B"
sudo /usr/local/bin/run_b.sh
fi
echo "<body>"
echo "<div id=\"content-container\">"
echo "<div id=\"content-container-center\">"
echo "<form id=\"choice\" name='form' method=\"POST\" action=\"/\">"
echo "<button id=\"a\" type=\"submit\" name=\"vote\" class=\"a\" value=\"a\">A</button>"
echo "<button id=\"b\" type=\"submit\" name=\"vote\" class=\"b\" value=\"b\">B</button>"
echo "</form>"
echo "<div id=\"tip\">"
echo "</div>"
echo "</div>"
echo "</div>"
echo "</div>"
echo "</body>"
echo "</html>"
Build with https://github.com/tinoschroeter/bash_on_steroids
I'm trying to build a form in Codeigniter so that its elements are part of a table and are therefore aligned nicely. Here's the view page:
<div id="login">
<h3>Log in</h3>
<?php
$attributes = array('id'=>'form_login');
echo validation_errors();
echo form_open('login/main', $attributes);
//probably a bad idea to load libraries in views, but what the heck?!
$this->load->library('table');
$this->table->add_row('Username', form_input('username'));
echo $this->table->generate();
//echo 'Username: ';
//echo form_input('username') . '</br>';
echo 'Password: ';
echo form_password('password') . '</br>';
echo form_submit('submit', 'Log in');
?>
<br/><br/>
Forgot Password <br/>
New User? Register
</div>
The two lines commented out is how it was earlier. Now I'm getting the following error: Call to a member function add_row() on a non-object. Why is table a non-object? I've tried loading the library in the controller but the error persists. Please help!
In codeigniter, the global codeigniter object is not available in your views, so you have to get a reference to it.
Try the following
$ci =& get_instance();
Put that at the top, and replace your calls to $this like so:
$ci->load->library('table');
$ci->table->add_row('Username', form_input('username'));
echo $ci->table->generate();
How could I add a logout link in the else portion of code, after the "echo $upme->display();" ...
<?php
global $upme;
if (!is_user_logged_in()) {
echo $upme->show_registration();
echo $upme->login();
}
else { echo $upme->display();
}
?>
I tried a few things including the below code but I keep getting internal error ...
<?php
global $upme;
$html1 = 'Logout';
if (!is_user_logged_in()) {
echo $upme->show_registration();
echo $upme->login();
}
else { echo $upme->display();
echo $html1;
}
?>
Thank You
There's a small syntax error:
$html1 = 'Logout';
500 is generally an "I can't find that" error. What page is this from? get_permalink may be returning false. Try outputting that function to see what you get back.
<?php echo get_permalink(); ?>
I want to launch a bash script when a button is pressed on a website.
This is my first attempt:
<button type="button" onclick="/path/to/name.sh">Click Me!</button>
But no luck. Any suggestions?
As stated by Luke you need to use a server side language, like php.
This is a really simple php example:
<?php
if ($_GET['run']) {
# This code will run if ?run=true is set.
exec("/path/to/name.sh");
}
?>
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
Click Me!
Save this as myfilename.php and place it on a machine with a web server with php installed. The same thing can be accomplished with asp, java, ruby, python, ...
This is really just an expansion of BBB's answer which lead to to get my experiment working.
This script will simply create a file /tmp/testfile when you click on the button that says "Open Script".
This requires 3 files.
The actual HTML Website with a button.
A php script which executes the script
A Script
The File Tree:
root#test:/var/www/html# tree testscript/
testscript/
├── index.html
├── testexec.php
└── test.sh
1. The main WebPage:
root#test:/var/www/html# cat testscript/index.html
<form action="/testscript/testexec.php">
<input type="submit" value="Open Script">
</form>
2. The PHP Page that runs the script and redirects back to the main page:
root#test:/var/www/html# cat testscript/testexec.php
<?php
shell_exec("/var/www/html/testscript/test.sh");
header('Location: http://192.168.1.222/testscript/index.html?success=true');
?>
3. The Script :
root#test:/var/www/html# cat testscript/test.sh
#!/bin/bash
touch /tmp/testfile
PHP is likely the easiest.
Just make a file script.php that contains <?php shell_exec("yourscript.sh"); ?> and send anybody who clicks the button to that destination. You can return the user to the original page with header:
<?php
shell_exec("yourscript.sh");
header('Location: http://www.website.com/page?success=true');
?>
Reference: http://php.net/manual/en/function.shell-exec.php
This is how it look like in pure bash
cat /usr/lib/cgi-bin/index.cgi
#!/bin/bash
echo Content-type: text/html
echo ""
## make POST and GET stings
## as bash variables available
if [ ! -z $CONTENT_LENGTH ] && [ "$CONTENT_LENGTH" -gt 0 ] && [ $CONTENT_TYPE != "multipart/form-data" ]; then
read -n $CONTENT_LENGTH POST_STRING <&0
eval `echo "${POST_STRING//;}"|tr '&' ';'`
fi
eval `echo "${QUERY_STRING//;}"|tr '&' ';'`
echo "<!DOCTYPE html>"
echo "<html>"
echo "<head>"
echo "</head>"
if [[ "$vote" = "a" ]];then
echo "you pressed A"
sudo /usr/local/bin/run_a.sh
elif [[ "$vote" = "b" ]];then
echo "you pressed B"
sudo /usr/local/bin/run_b.sh
fi
echo "<body>"
echo "<div id=\"content-container\">"
echo "<div id=\"content-container-center\">"
echo "<form id=\"choice\" name='form' method=\"POST\" action=\"/\">"
echo "<button id=\"a\" type=\"submit\" name=\"vote\" class=\"a\" value=\"a\">A</button>"
echo "<button id=\"b\" type=\"submit\" name=\"vote\" class=\"b\" value=\"b\">B</button>"
echo "</form>"
echo "<div id=\"tip\">"
echo "</div>"
echo "</div>"
echo "</div>"
echo "</div>"
echo "</body>"
echo "</html>"
Build with https://github.com/tinoschroeter/bash_on_steroids
Nope. Ignore this. The space is put there by browser.
This is a HTML snippet from my application:
Correct answers:
0 / 6<br /><br />
You have failed to pass the final test.
<a href="/module/controller/course/id/5" class="accessible-link">
Click here
</a>
to return to the training.
As you can see, there is a single space after the </a> closing tag. Yet in the browser the space is added inside the anchor. So it looks like this:
This is the PHP code which produces the HTML:
<?php if (isset($this->correctAnswersCount) && isset($this->answersCount)): ?>
<?php echo Zend_Registry::get('translate')->_('Počet správnych odpovedí'); ?>:
<?php echo ToHtml($this->correctAnswersCount); ?> / <?php echo ToHtml($this->answersCount); ?><br /><br />
<?php endif; ?>
<?php echo Zend_Registry::get('translate')->_('Záverečný test sa vám nepodarilo úspešne absolvovať.'), "\n"; ?>
<a href="<?php echo ToHtml($this->backToCourseUri); ?>" class="accessible-link">
<?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?>
</a>
<?php echo Zend_Registry::get('translate')->_('pre návrat do kurzu.'), "\n"; ?>
I am completely baffled by this and cannot figure out what's causing this even though I've been staring into the code for 30 minutes now.
This is a relevant part from the translation file:
'Kliknite' => 'Click here',
As you can see, there should be no space added by Zend_Translate.
Change this:
<a href="<?php echo ToHtml($this->backToCourseUri); ?>" class="accessible-link">
<?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?>
</a>
Into this:
<a href="<?php echo ToHtml($this->backToCourseUri); ?>" class="accessible-link">
<?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?></a>
The </a> should be in the same line after the <?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?> aka Click Here
EDIT:
The new line and the spaces after it renders like 1 space that is still inside de <a></a> tags, that is where the blank space is coming from.
EDIT2:
For the record I also don't like the closing tag to be next to the content instead of a being in a new line but that's how it has to be done in order to work correctly.
I like good formatted code and I always look for a autoformat command in my IDE.
But at least for example in Visual Studio when you hit Ctrl + K, Ctrl + D (the Format Document shorcut) the closing tags like the </a> are not automatically moved to a new line for this exact reason: that it should not break the way it looks before the auto format.
Close the 'a' tag directly after the next, without a newline, like this:
Click here
Try it like this:
Click here
I am not sure if this will work, but it is worth trying.
Put immediately after the </a> tag.